2020年6月18日 星期四

08160226_week17

float x=200,y=150;
float vx=0,vy=0;
void setup()
{
  size (300,300);
}
void draw()
{
  background(#FFFFFF);
  stroke(#000000);
  line(100,150, x,y);
  
  fill(#000000);
  noStroke();
  ellipse(100,150, 13,13);
  ellipse(x,y, 13,13);
  if( ! mousePressed){
    float dx=x-100, dy=y-150;
    float len=sqrt(dx*dx+dy*dy);
    vx -=dx*(len-100)/len*0.001;
    vy -=dy*(len-100)/len*0.001;
    x += vx;
    y += vy;
  }
}
void mouseDragged()
{
  x = mouseX;  y = mouseY;
}

沒有留言:

張貼留言