2025年3月27日 星期四

12750892-黃聖諺-week06

 //week06-1
void setup(){
  size(500, 500, P3D);
}
void draw(){
  background(142);
  ellipse(width/2, height/2, 200, 200);
  
  translate(width/2, height/2);
  pushMatrix();
    if(mousePressed) rotateZ(radians(frameCount));
    box(100, 30, 30);
  popMatrix();
}


//week06_2
void setup(){
  size(500, 500, P3D);
}
void draw(){
  background(142);
  ellipse(width/2, height/2, 200, 200);
  
  translate(width/2, height/2);
  pushMatrix();
    if(mousePressed) rotateZ(radians(frameCount));
    translate(-50, 0, 0);
    box(100, 30, 30);
  popMatrix();
}

//week06_3_push_translate_rotate_translate_box_pop

void setup(){
  size(500,500,P3D);
}
void draw(){
  background(142);
  ellipse(width/2, height/2, 200, 200);
  translate(width/2, height/2);
  pushMatrix();
    translate(x,y);
    if(mousePressed && mouseButton == RIGHT){
      rotateZ(radians(frameCount));
    }
    translate(-50, 0, 0);
    box(100, 30, 30);
  popMatrix();
}
float x = 0,y = 0;
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
}


//week06_4_sphere_box_push_T_R_T_box_pop
//慢慢組合出機器手臂
void setup(){
  size(500, 400, P3D);
}
void draw(){
  background(255); //step00
  translate(width/2, height/2); //step00
  sphere(10); //step04 放個圓球,當世界中心的參考
  
  box(200, 50, 25); //step05 手肘
  
  fill(252, 131, 77);
  pushMatrix(); //step03
    translate(x, y); //step06
    if(mousePressed) rotateZ(radians(frameCount)); //step03
    translate(25, 0, 0); // step02 往右推,讓左端放中心
    box(50, 25, 50); // step01 小手腕
  popMatrix(); //step03
}
float x = 0, y = 0; //step06 會動的位置
void mouseDragged(){ //step06
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
  println("x:" + x + " y:" + y); //step07 印出來
}


//week06_5
//慢慢組合出機器手臂
void setup(){
  size(500, 400, P3D);
}
void draw(){
  background(255);
  translate(width/2, height/2);
  sphere(10);
  
  fill(252, 131, 77);
  
  pushMatrix(); //step04 新的一組
    translate(x, y); //step05 新的轉動
    box(200, 50, 25); //step05 手肘(剛剛放錯位置)
    
    pushMatrix(); //step03 把程式往右縮排
      translate(100, 0); //step01 把前一步發現的 100,0 放好
      //if(mousePressed) rotateZ(radians(frameCount));
      rotateZ(radians(frameCount)); //step02 把剛剛的if(mousePressed) 刪掉,只轉動
      translate(25, 0, 0); //往右推,讓左端放中心
      box(50, 25, 50); //小手腕
    popMatrix(); //step03把程式往右縮排
  popMatrix(); //step04 新的一組
}
float x = 0, y = 0; //會動的位置
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
  println("x:" + x + " y:" + y); //step07 印出來
}

//week06_6_push_box_push_TRT_box_push_TRT_box_pop_pop_pop
//慢慢組合出機器手臂
void setup(){
  size(500, 400, P3D);
}
void draw(){
  background(255);
  translate(width/2, height/2);
  sphere(10);
  
  fill(252, 131, 77);
  pushMatrix(); //step04 push
  //step05 裡面要往右縮排
    box(50, 200, 25); //step03 手臂
    pushMatrix();
      translate(x,y); //step03:掛在手臂上面,觀察到 0,-100
      if(mousePressed) rotateZ(radians(frameCount)); //step02 把旋轉放入
      translate(100, 0); //step01 把手肘的移動量100,0 放入
      box(200, 50, 25); //手肘
      
      pushMatrix(); 
        translate(100, 0);
        rotateZ(radians(frameCount)); 
        translate(25, 0, 0); 
        box(50, 25, 50); //小手腕
      popMatrix();
    popMatrix();
  popMatrix();
}
float x = 0, y = 0; //會動的位置
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
  println("x:" + x + " y:" + y); //step07 印出來
}



//week06_7_push_RRT_many_TRT__inside_pop
//慢慢組合出機器手臂
void setup(){
  size(500, 800, P3D);
}
void draw(){
  background(255);
  translate(width/2, height/2);
  sphere(10);
  
  fill(252, 131, 77);
  pushMatrix(); 
    if(mousePressed && mouseButton == RIGHT) rotateY(radians(frameCount)); //step03 右鍵旋轉
    if(mousePressed && mouseButton == RIGHT) rotateZ(radians(frameCount)); //step02 右鍵旋轉
    translate(0,-100); //step01 要往上抬升,把關節移到中心
    box(50, 200, 25); //手臂
    pushMatrix();
      translate(0, -100); //step00 掛在手臂上面,觀察0,-100 
      //if(mousePressed)  //step00 把 if(mousePressed) 刪掉,讓他一直轉
      rotateZ(radians(frameCount)); 
      translate(100, 0); 
      box(200, 50, 25); 
      
      pushMatrix(); 
        translate(100, 0);
        rotateZ(radians(frameCount)); 
        translate(25, 0, 0); 
        box(50, 25, 50);  //手肘
      popMatrix();
    popMatrix();
  popMatrix();
}
float x = 0, y = 0;
void mouseDragged(){
  x += mouseX - pmouseX;
  y += mouseY - pmouseY;
  println("x:" + x + " y:" + y); 
}

//week06-8 github 上傳













沒有留言:

張貼留言