2025年3月13日 星期四

week04-12750441

week04

week04_01_atan2_dy_dx_con_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);

}















week04_02_atan2_for_x_dx_dt_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);
  }
}














week04_03_rotate_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);
}














week04_04_rotateZ_

void setup(){
  size(400,400,P3D);
}

void draw(){
   background(128);
   translate(width/2,height/2);
   rotateZ(radians(-mouseY));//換旋轉Z軸
   ellipse(0,0,100,150);
}













week04_05_robot_arm_pushMAtrix_T_R_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));
       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(mouseX));//對Z軸旋轉
       translate(0,-50);//把下端,移到中心
       box(10,100,10);//可轉動的長條

}














week04_05b_translate_mouseX_mouseY

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);//可轉動的長條

}














week04_06_robot_arm_pushMatrix

void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  pushMatrix();
    translate(mouseX,mouseY);
    rotate(radians(frameCount));
    sphere(100);
  popMatrix();
}














week04_07_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);
    rotate(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);
    rotate(radians(frameCount));
    sphere(30);
    pushMatrix();
      translate(50,0);
      rotateY(radians(frameCount));
      sphere(10);
     popMatrix();
  popMatrix();
}














week04_09_earth_textture

PImage img = loadImage("earth.jpg");
size(600,300);
image(img,0,0,600,300);













week04_10_earth_createShape_setTexture_shape

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














week04_11_earth

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

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

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
//樓下剪貼
PShape sun,earth,moon;
void setup(){
  size(400,400,P3D);
  earth = createShape(SPHERE,30);
  PImage img = loadImage("earth.jpg");
  earth.setTexture(img);
  
  size(400,400,P3D);
  moon = createShape(SPHERE,10);
  img = loadImage("moon.jpg");
  moon.setTexture(img);
  
  size(400,400,P3D);
  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);
    rotate(radians(frameCount));
    shape(earth);
    pushMatrix();
      translate(50,0);
      rotateY(radians(frameCount));
      shape(moon);
     popMatrix();
  popMatrix();
}


沒有留言:

張貼留言