2025年3月13日 星期四

12750530李忻穎_week04

作業1:畫出一個眼睛
程式碼:
//week04_01_atan2_dy_dx_cos_sin
void setup(){
  size(600,300);
}
void draw(){
  background(#C0FFEE);
  ellipse(150,150,100,100);
  float dx =mouseX-150, dy=mouseY-150;
  float a=atan2(dy,dx);
  ellipse(150+cos(a)*25, 150+sin(a)*25,50,50);
}
執行結果:
























作業2:用迴圈,兩顆眼睛
程式碼:
//week04_02_atan2_dy_dx_cos_sin
void setup(){
  size(600,300);
}
void draw(){
  background(#C0FFEE);
  for(int x=150;x<=450;x+=300){
    ellipse(x,150,100,100);
    float dx =mouseX-x, dy=mouseY-150;
    float a=atan2(dy,dx);
    ellipse(x+cos(a)*25, 150+sin(a)*25,50,50);
  }

}
執行結果:



















作業3:對X軸旋轉
程式碼:
//week04_03_rotateX_radians_mouseY
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2, height/2);
  //rotateY(radians(mouseX)); //上周的左右轉
  rotateX(radians(mouseY)); //這周的上下轉
  box(200);
}
執行結果:
























作業4:對Z軸旋轉
程式碼:
//week04_04_rotateZ_radians_mouseY
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2, height/2);
  //rotateY(radians(mouseX)); //上周的左右轉
  rotateZ(radians(mouseY)); //這周的上下轉
  ellipse(0,0,100,150);
}
執行結果:


















作業5:機器手臂
程式碼:
//week04_05_robot_arm_pushMatrix_T_R_T_box_popMatrix
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2, height/2);
  pushMatrix();
    translate(0,100);
    box(50);
    pushMatrix();
      rotateZ(radians(mouseX));
      translate(0,-50);
      box(10,100,10);
      popMatrix();
    popMatrix();
}
執行結果:






























作業5a:對端點轉動
程式碼:
//week04_05a_rotateZ_translate_box
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2, height/2); //移至畫面中心
  
      //以下兩行,分別註解,排列組合觀察
      rotateZ(radians(frameCount)); //對Z軸旋轉
      //translate(0,-50); //把下端,移到中心
      box(10,100,10); //可轉動的長條
}
執行結果:

作業5b:
程式碼:
//week04_05b_translate_mouseX_mouseY_rotateZ_translate_box
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  //translate(width/2, height/2); //移至畫面中心
  
      translate(mouseX,mouseY); //加這行
      rotateZ(radians(frameCount)); //對Z軸旋轉
      //translate(0,-50); //把下端,移到中心
      box(10,100,10); //可轉動的長條
}
執行結果:













作業6:
程式碼:
//week04_06_push_translate_rotate_sphere_pop
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  pushMatrix();
      translate(mouseX,mouseY); 
      rotateY(radians(frameCount)); 
      sphere(100);
   popMatrix();
}
執行結果:



作業7:地球繞著太陽轉
程式碼:
//week04_07_sun_earth
void setup(){
      size(400,400,P3D);
    }
    void draw(){
      background(128);
      translate(width/2, height/2);
      sphere(100);
      rotateY(radians(frameCount));
      pushMatrix();
          translate(150,0); 
          rotateY(radians(frameCount)); 
          sphere(30);
         popMatrix();
    }
    執行結果:
























作業8:地球跟月球繞著太陽轉
程式碼:
//week04_08_sun_earth_moon
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2, height/2);
  sphere(100);
  rotateY(radians(frameCount));
  pushMatrix();
      translate(150,0); 
      rotateY(radians(frameCount)); 
      sphere(30); //地球
      pushMatrix();
        translate(50,0); 
        rotateY(radians(frameCount)); 
        sphere(10); //月球
      popMatrix();
   popMatrix();
}
執行結果:
































作業9:
程式碼:
//week04_09_earth_texture_image
//google: earth map texture 下載1張地球的地圖 earth.jpg
//把圖檔拉到程式裡面
PImage img = loadImage("earth.jpg");
size(600,300);
image(img,0,0,600,300);
執行結果:










作業10:
程式碼:
//week04_10_earth_createShape_setTexture_shape
//google: processing sphere texture 可找到程式
size(400,400,P3D);
PShape earth = createShape(SPHERE, 100);
PImage img= loadImage("earth.jpg");
earth.setTexture(img);
shape(earth);
執行結果:
作業11:地球的貼圖
程式碼:
//week04_11_earth_setTexture_trandlate_rotate
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);
}
執行結果:



作業12:月球的貼圖
程式碼:
//week04_12_moon_setTexture_trandlate_rotate
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);
}
執行結果:















作業13:太陽的貼圖
程式碼:
//week04_13_sun_setTexture_trandlate_rotate
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);
}
執行結果:






















作業14:
程式碼:
//week04_14_sun_earth_moon_setTexture
PShape sun, earth, moon;
//樓下,剪貼自 week04_08, 樓上, 是week04_11_12_13
void setup(){
  size(400,400,P3D);
  sun = createShape(SPHERE, 50);
  PImage img = loadImage("sun.jpg");
  sun.setTexture(img);
  
  earth = createShape(SPHERE, 30);
  img = loadImage("earth.jpg");
  earth.setTexture(img);
  
  moon = createShape(SPHERE, 10);
  img = loadImage("moon.jpg");
  moon.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();
}
執行結果:


沒有留言:

張貼留言