2025年3月27日 星期四

12750512 林政杰 week06

  week06-1  

指針在中間旋轉

程式碼:
//week06-1 ellipse_translate-push rotate
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 

translate這一行 讓指針沿著外圍旋轉

程式碼:

//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

 讓小方塊能夠自由移動

程式碼:

//week06-3

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_box_pop
//慢慢組出機器手臂
void setup(){
  size(500,400,P3D);
}
void draw(){
  background(255);//step 00
  translate(width/2,height/2);//step00
  sphere(10);//step04 放個圓球,當世界中心的參考
  box(200,50,25);//手肘
  fill(252,131,77);
  pushMatrix();//step03
   translate(x,y);//step 06發現放100,0很好
    if(mousePressed) rotateZ(radians(frameCount));//step03
    translate(25,0,0);//step 02往又推,讓左端放中心
    box(50,25,50);//step 01小手腕
  popMatrix();//step 03
}
float x=0,y=0;//step 06會動的位置
void mouseDragged(){  //srep 06
  x+=mouseX-pmouseX;
  y+=mouseY-pmouseY;
  println("x:"+x+"y:"+y);// step 07 印出來(用java寫法)
 }

week06-5
可以把機器手臂一出世界的中心,又新增加一組push,pop
程式碼:

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


}
    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();//step 04 push
    //step05 裡面要往右縮排一個tab
    box(50,200,25);//step03手臂
    pushMatrix();
      translate(x,y);//step 03 掛到手臂上面,觀察0,-100
      if(mousePressed) rotateZ(radians(frameCount));//把旋轉放入
      translate(100,0);//step 01把手肘移動100,0放入
      box(200,50,25);//  手肘
      
      pushMatrix();
       translate(100,0);
        //if(mousePressed) rotateZ(radians(frameCount));//step03
        rotateZ(radians(frameCount));
        translate(25,0,0);
        box(50,25,50);//小手腕
      popMatrix();
    popMatrix();
  popMatrix();//step04 pop
}
float x=0,y=0;//step 06會動的位置
void mouseDragged(){  //srep 06
  x+=mouseX-pmouseX;
  y+=mouseY-pmouseY;
  println("x:"+x+"y:"+y);// step 07 印出來(用java寫法)
 }

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(x,y);//step 01要往上抬升0,-100,到中心
    box(50,200,25);//手臂
    pushMatrix();
      translate(0,-100);//step 00: 掛到手臂上面,觀察0,-100
      //if(mousePressed) //step00 把if(mousePressed) 刪掉,讓他一直轉
      rotateZ(radians(frameCount));
      translate(100,0);//step 01把手肘移動100,0放入
      box(200,50,25);//  手肘
      
      pushMatrix();
       translate(100,0);
        //if(mousePressed) rotateZ(radians(frameCount));//step03
        rotateZ(radians(frameCount));
        translate(25,0,0);
        box(50,25,50);//小手腕
      popMatrix();
    popMatrix();
  popMatrix();//step04 pop
}
float x=0,y=0;//step 06會動的位置
void mouseDragged(){  //srep 06
  x+=mouseX-pmouseX;
  y+=mouseY-pmouseY;
  println("x:"+x+"y:"+y);// step 07 印出來(用java寫法)
 }





沒有留言:

張貼留言