2025年3月13日 星期四

12750290

 //week04-01-atan2-dx-dy

利用角度劃出圓和小圓

void setup(){
  size(600,300);
}
void draw(){
  background(#C0FFEE);
  ellipse(150,150,100,100);
  //ellipse(150+25,150,50,50);
  float dx=mouseX-150,dy=mouseY-150;
  float a= atan2(dy,dx);
  ellipse(150+cos(a)*25,150+sin(a)*25,50,50);
}


//week04-02-atan2-for-dx-dy
利用FOR做出兩個一樣的圓圈
void setup(){
  size(600,300);
}
void draw(){
  background(#C0FFEE);
  for(int x=150;x<=450;x+=300){
    ellipse(150,150,100,100);
    //ellipse(150+25,150,50,50);
    float dx=mouseX-150,dy=mouseY-150;
    float a= atan2(dy,dx);
    ellipse(150+cos(a)*25,150+sin(a)*25,50,50);
  }
}

//week04-03-rotateY-radians-mouseX
由上週教的左右轉改成這周的上下轉
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  //rotateY(radians(mouseX));
  rotateX(radians(mouseY));
  box(200);
}

//week04-04-rotateZ
改成Z旋轉
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  rotateZ(radians(mouseX));
  ellipse(0,0,100,150);
}

//week04-05-robot-arm
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  pushMatrix();
    translate(0,100);
    box(50);
    pushMatrix();
      translate(0,-25);
      rotateZ(radians(mouseX));
      translate(0,-50);
      box(10,100,10);
    popMatrix();
  popMatrix();
}

//week04-05a-rotateZ-translate-box void setup(){ size(400,400,P3D); } void draw(){ background(128); translate(width/2,height/2); rotateZ(radians(frameCount)); translate(0,-50); box(10,100,10); }


//week04-05b-rotateZ-translate-box
改成指針隨著滑鼠移動
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  //translate(width/2,height/2);
    translate(mouseX,mouseY);
    rotateZ(radians(frameCount));
    translate(0,-50);
    box(10,100,10);
}

//week04-06
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  pushMatrix();
    translate(mouseX,mouseY);
    rotateY(radians(frameCount));
    sphere(100);
  popMatrix();
}


//week04-07
再加一個球球繞著他轉
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  sphere(50);
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150,0);
    rotateY(radians(frameCount));
    sphere(30);
  popMatrix();
}

//week04-08-sun-earth-moon
做出太陽地球月球
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  sphere(50);
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150,0);
    rotateY(radians(frameCount));
    sphere(30);
    pushMatrix();
      translate(50,0);
      rotateY(radians(frameCount));
      sphere(10);
    popMatrix();
  popMatrix();
}

//week04-09-earth-texture
找地球圖片貼上去
PImage img = loadImage("earth.jpg");
size(600,300);
image(img,0,0,600,300);

//week04-10-earth
size(400,400,P3D);
PShape earth=createShape(SPHERE,100);
PImage img=loadImage("earth.jpg");
earth.setTexture(img);
shape(earth);

//week04-11-earth-setTexture-translate
畫出圓形旋轉地球
PShape earth;
void setup(){
  size(400,400,P3D);
  earth=createShape(SPHERE,100);
  PImage img=loadImage("earth.jpg");
  earth.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(earth);
}

//week04-12-moon-setTexture-translate
改成月亮
PShape moon;
void setup(){
  size(400,400,P3D);
  moon=createShape(SPHERE,100);
  PImage img=loadImage("moon.jpg");
  moon.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(moon);
}
//week04-13-sun-setTexture-translate
改成太陽
PShape sun;
void setup(){
  size(400,400,P3D);
  sun=createShape(SPHERE,100);
  PImage img=loadImage("sun.jpg");
  sun.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(sun);
}
//week04-14-sun-earth-moon-setTexture
把太陽地球月亮合起來
PShape sun,earth,moon;
void setup(){
  size(400,400,P3D);
  
  earth=createShape(SPHERE,30);
  PImage img=loadImage("earth.jpg");
  earth.setTexture(img);
  
  moon=createShape(SPHERE,10);
  img=loadImage("moon.jpg");
  moon.setTexture(img);
  
  sun=createShape(SPHERE,50);
  img=loadImage("sun.jpg");
  sun.setTexture(img);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  shape(sun);
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150,0);
    rotateY(radians(frameCount));
    shape(earth);
    pushMatrix();
      translate(50,0);
      rotateY(radians(frameCount));
      shape(moon);
    popMatrix();
  popMatrix();
}













沒有留言:

張貼留言