//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();
if(mousePressed) rotateZ(radians(frameCount));//要按下mouse才會轉
box(100,30,30);
popMatrix();
}
//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();
if(mousePressed) rotateZ(radians(frameCount));//要按下mouse才會轉
translate(-50,0,0);//把棒子往左移一半
box(100,30,30);
popMatrix();
}
//week06_3_push_translate_totate_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));//要按下mouse才會轉
}
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);
translate(width/2,height/2);
sphere(10);//STEP04 放圓球用來參考座標中心
box(200,50,25);//STEP05手肘
fill(252,131,77);
pushMatrix();//STEP03
translate(x,y);//STEP 06 發現放100,0 GOOD
if(mousePressed) rotateZ(radians(frameCount));//STEP03
translate(25,0,0);//STEP2往又推讓左端放中心
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();//STEP04新的一組
translate(x,y);
box(200,50,25);//STEP05手肘
//step03把程式往右縮排
pushMatrix();
translate(100,0);// STEP01 發現放100,0 GOOD
//if(mousePressed) rotateZ(radians(frameCount));
rotateZ(radians(frameCount));//STEP02把前面if刪掉。只轉動
translate(25,0,0);//往又推讓左端放中心
box(50,25,50);// 小手腕
popMatrix();
popMatrix();//STEP04新的一組
}
float x=0,y=0;// 會動的位置
void mouseDragged(){
x+=mouseX-pmouseX;
y+=mouseY-pmouseY;
println("X:"+x+"Y:"+y);
}
//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();
box(50,200,25);//STEP03 ARM
pushMatrix();
translate(x,y);//STEP03 掛到手臂上關柴到0,-100
if(mousePressed) rotateZ(radians(frameCount));//step2 把旋轉放入
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();//STEP04新的一組
popMatrix();
}
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) rotateY(radians(frameCount));//step03 向右旋轉
if(mousePressed && mouseButton==RIGHT) rotateZ(radians(frameCount));//step02 向右旋轉
translate(0,-100);
//translate(x,y);//step01 往上抬升到中心
box(50,200,25);// ARM
pushMatrix();
translate(0,-100);//STEP00 掛到手臂上關柴到0,-100
//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);
}







沒有留言:
張貼留言