2020年6月19日 星期五

week17

Processing 拉線

void setup(){
  size(300,300);
}
float x=100,y=150;
void draw(){
  background(#002966);
  stroke(#b7efff);
  line(x,y,200,150);

  fill(#b7efff);
  ellipse(x,y,13,13);
  ellipse(250,150,13,13); //如果mouse放開 , 就讓 x,y 慢慢接近200,150;
  if (! mousePressed){
    float dx=x-200;
    float dy=y-150;
    float len=sqrt(dx*dx+dy*dy);
    x -= dx*(len-100)/len*0.1;
    y -= dy*(len-100)/len*0.1; //0.1快,001慢
  }
 }
 void mouseDragged(){
   x=mouseX;y=mouseY;
 }

沒有留言:

張貼留言