2025年3月27日 星期四

12751036-徐詩淳_week06

 








// week06_1_ellipse_translate_push_rotate_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(); // 第五周教過的Matrix保護

    if(mousePressed) rotateZ(radians(frameCount)); 

    box(100, 30, 30); // 橫的棒子

  popMatrix(); // 第五周教過的Matrix保護

}









// week06_2_ellipse_translate_push_rotate_translate_box_pop

// 再加1個移動,把物體放到[旋轉中心]

void setup(){

  size(500, 500, P3D);

}

void draw(){

  background(142);

  ellipse(width/2, height/2, 200, 200);

  

  translate(width/2, height/2); // 把東西放正中心

  pushMatrix(); // 第五周教過的Matrix保護

    if(mousePressed) rotateZ(radians(frameCount)); 

    translate(-50, 0, 0); //棒子左移

    box(100, 30, 30); // 橫的棒子

  popMatrix(); // 第五周教過的Matrix保護

}











// 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(); // 第五周教過的Matrix保護

    translate(x, y);

    if(mousePressed && mouseButton==RIGHT){

      rotateZ(radians(frameCount)); 

    } 

    translate(-50, 0, 0); //棒子左移

    box(100, 30, 30); // 橫的棒子

  popMatrix(); // 第五周教過的Matrix保護

}

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); // step03

  pushMatrix();

  translate(x, y); // step06

    if(mousePressed) rotate(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_push_T_box_push_T_R_T_box_pop_pop

// 慢慢組合出機器手臂

void setup(){

  size(500, 400, P3D);

}

void draw(){

  background(255);

  translate(width/2, height/2);

  sphere(10); 

  

  fill(252, 131, 77); 

  pushMatrix(); // step03

    translate(x,y); // step03

    box(200, 50, 25);

  

    pushMatrix();

      translate(100, 0); // step01 把前一步發現的 100,0 放好

      // if(mousePressed) rotateZ(radians(frameCount)); 

      rotateZ(radians(frameCount));  // step02 只轉動

      translate(25, 0, 0);

      box(50, 25, 50); 

    popMatrix(); 

  popMatrix();

}

float x = 0, y = 0;

void mouseDragged(){

  x += mouseX - pmouseX;

  y += mouseY - pmouseY;

  println("x:" + x + "y:" + y); 

}










// week06_6_push_box_TRT_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(); 

    box(50, 200, 25); // step03: arm

    pushMatrix();

      translate(x,y); // step03: 掛到手臂上面

      if(mousePressed) rotateZ(radians(frameCount));

      translate(100,0);  // step01

      box(200, 50, 25); // 手肘

    

      pushMatrix();

        translate(100, 0); 

        rotateZ(radians(frameCount)); 

        translate(25, 0, 0);

        box(50, 25, 50); 

      popMatrix();

    popMatrix(); 

  popMatrix(); // step04 pop

}

float x = 0, y = 0;

void mouseDragged(){

  x += mouseX - pmouseX;

  y += mouseY - pmouseY;

  println("x:" + x + "y:" + y); 

}







// week06_7_push_RRT_many_TRT_inside_pop

// 慢慢組合出機器手臂

void setup(){

  size(500, 800, P3D); // step00: 視窗拉長 看比較完整

}

void draw(){

  background(255);

  translate(width/2, height/2);

  sphere(10); 

  

  fill(252, 131, 77);  

  pushMatrix(); 

    if(mousePressed && mouseButton==RIGHT) rotateZ(radians(frameCount)); // step02

    if(mousePressed && mouseButton==RIGHT) rotateZ(radians(frameCount)); // step02

    translate(0,-100); //translate(x,y); // step01: 抬升

    box(50, 200, 25); // 手臂

    pushMatrix();

      translate(0,-100); // step00: 掛在手臂上

      // if(mousePressed) // step00: delete

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

}








沒有留言:

張貼留言