2025年3月13日 星期四

12750211-week04

1.

//week04-1_atan2_dy_dx_cos_sin

void setup(){

  size(600,480);

}

void draw(){

   background(#C0FFEE);

   ellipse(150,150,100,100);

   //ellipse(175,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,480);
}
void draw(){
   background(#C0FFEE);
   for(int x=150;x<=450;x+=300){
     ellipse(x,150,100,100);
     float dx=mouseX-150,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);
  //rotateY(radians(mouseX)); //左右
  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));
      translate(0,-50);
      box(10,100,10);
     popMatrix();
    popMatrix();
}


5a.//week04-5a_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-5b_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-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);//太陽
  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-9_Earth_texture_Image
PImage img=loadImage("earth.jpg");
size(600,300);
image(img,0,0,600,300);
10.//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);


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_setTexture
PShape earth,moon,sun;
void setup(){
  size(400,400,P3D);
  
  earth=createShape(SPHERE,30);
  PImage img=loadImage("earth.jpg");
  earth.setTexture(img);
  
  sun=createShape(SPHERE,50);
  img=loadImage("sun.jpg");
  sun.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();
}

 


沒有留言:

張貼留言