2025年3月13日 星期四

week04-12750724

 課堂作業1

//week04_1_atan2_dy_dx_cos_sin
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);
}



課堂作業2

//week04_2_atan2_for_x_dx_dy_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

//week04_3_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

//week04_4_rotateZ
void setup()
{
  size(400, 400, P3D);
}
void draw()
{
  background(128);
  translate(width / 2, height / 2);
  rotateZ(radians(-mouseX));
  ellipse(0, 0, 100, 150);
}




課堂作業5

//week04_5_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();
    translate(0, -25);
    rotateZ(radians(mouseX));//對Z軸旋轉
    translate(0, -50);//把下端移到中心
      box(10, 100, 10);
     popMatrix();
    popMatrix();
}

//week04_5a_rotateZ_translate_box
void setup()
{
  size(400, 400, P3D);
}
void draw()
{
  background(128);
  translate(width / 2, height / 2);//移到畫面中
  
    //以下2行分別註解、排列組合觀察
    rotateZ(radians(frameCount));//對Z軸旋轉
    translate(0, -50);//把下端移到中心
    box(10, 100, 10);//可轉動的長條
}


//week04_5b_tranlate_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_6_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_7_sun_earth
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();
}



課堂作業8
//week04_8_sun_earth_moon
void setup()
{
  size(400, 400, P3D);
}
void draw()
{
  background(128);
  translate(width / 2, height / 2);
  sphere(50);//sun
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150, 0);
    rotateY(radians(frameCount));
    sphere(30);//earth
     pushMatrix();
      translate(50, 0);
      rotateY(radians(frameCount));
      sphere(10);//moon
     popMatrix();
    popMatrix();
}


課堂作業9
//week04_9_earth_texture
//google:earth map texture下載1張地球的地圖
//把圖片拉到程式
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_translate_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_translate_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_translate_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_Texture
PShape sun, earth, moon;
//下面是week04_8, 上面是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);//sun
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150, 0);
    rotateY(radians(frameCount));
    shape(earth);//earth
     pushMatrix();
      translate(50, 0);
      rotateY(radians(frameCount));
      shape(moon);//moon
     popMatrix();
    popMatrix();
}





沒有留言:

張貼留言