2025年3月27日 星期四

week06

 

week06-1

//week06-1_ellipse_translate_push_box_pop
//有點模仿第4週的程式,慢慢建出來
void setup(){
  size(500,500,P3D);
}
void draw(){
  background(142);
  ellipse(width/2, height/2, 200, 200);
  translate(width/2, height/2);//把東西放中間
  pushMatrix();
    //改一下,要按下mouse才轉
    if(mousePressed)rotateZ(radians(frameCount));//對著下面中心旋轉
    box(100, 30, 30);//橫的棒子
  popMatrix();
}


week06-2

//week06-2_ellipse_translate_push_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();

    //改一下,要按下mouse才轉

    if(mousePressed)rotateZ(radians(frameCount));//對著下面中心旋轉

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

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

  popMatrix();

}


week06-3

//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
//week06-4_sphere_box_push_T_R_T_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 發現放 100,0 很好
    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

//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();
    translate(x, y);
     box(200,50,25);//手肘
    pushMatrix();//step03 把程式往右縮排
      translate(100, 0);//step01 發現放 100,0 很好
      //if(mousePressed) // step02 把剛剛的if(mousePressed)刪掉
      rotateZ(radians(frameCount));
      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);// step07 印出來
}

week06-6
//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));// 把旋轉放入
      translate(100,0);//step0:把手肘的移動量100,0放入
      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);// step07 印出來
}

week06-7
//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)rotateY(radians(frameCount));//step03:右鍵旋轉
    if(mousePressed && mouseButton==RIGHT)rotateZ(radians(frameCount));//step02:右鍵旋轉
    translate(0,-100);//translate(x, y);//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);// step07 印出來
}





沒有留言:

張貼留言