01.Java程式:圓心旋轉點:
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();
}
02.Java程式:圓心旋轉點+鼠標拖曳:
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;
}
03.Java程式:手臂旋轉:
void setup(){
size(500,500,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();
translate(100,0);
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;
}
沒有留言:
張貼留言