2020年6月18日 星期四

程式設計 week17



void setup(){
    size(300,300);
}
void draw(){
    background(#002966);///填充背景顏色
    fill(#b7efff);
    noStroke();
    ellipse(100,150, 13,13);///放原點
    ellipse(200,150, 13,13);
}



void setup(){
    size(300,300);
}
void draw(){
    background(#002966);
    stroke(#b7efff);
    line(100,150, 200,150);///拉白線
   
    fill(#b7efff);
    noStroke();
    ellipse(100,150, 13,13);
    ellipse(200,150, 13,13);
}



void setup(){
    size(300,300);
}
float x=200, y=150;
void draw(){
    background(#002966);
    stroke(#b7efff);
    line(100,150, x,y);
   
    fill(#b7efff);
    noStroke();
    ellipse(100,150, 13,13);
    ellipse(x,y, 13,13);///第二顆球設變數可移動
}

void mouseDragged(){
    x=mouseX; y=mouseY;
}



void setup(){
    size(300,300);
}
float x=200, y=150;
void draw(){
    background(#002966);
    stroke(#b7efff);
    line(100,150, x,y);
   
    fill(#b7efff);
    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);
      x -= dx*(len-100)/len*0.1;
      y -= dy*(len-100)/len*0.1;///*0.1讓回彈更滑順
    }///滑鼠放開彈回
}



void mouseDragged(){
    x=mouseX; y=mouseY;
}





void setup(){
    size(300,300);
}
float x=200, y=150;
float vx=0, vy=0;
void draw(){
    background(#002966);
    stroke(#b7efff);
    line(100,150, x,y);
   
    fill(#b7efff);
    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;
      x += vy;
    }
}



void mouseDragged(){
    x=mouseX; y=mouseY;
}




void setup(){
    size(400,300);
}
float x=200, y=150;
void draw(){
    background(#002966);
    fill(255);
    rect(x,y, 80,20);
    float dx=x-mouseX, dy=y-mouseY;
   
    x -= dx*0.1;
    y -= dy*0.1;
    }

沒有留言:

張貼留言