01.Java程式:眼睛:
void setup(){
size(600,600);
}
void draw(){
background(#C0FFEE);
fill(255);
ellipse(150,150,100,100);
float dx = mouseX-150, dy = mouseY-150;
float a = atan2(dy,dx);
fill(0);
ellipse(150+cos(a)*25,150+sin(a)*25, 50, 50);
}
02.Java程式:兩顆眼睛
void setup() {
size(600, 600);
}
void draw() {
background(#C0FFEE);
for (int x = 150; x<=450; x+=300) {
fill(255);
ellipse(x, 150, 100, 100);
float dx = mouseX-150, dy = mouseY-150;
float a = atan2(dy, dx);
fill(0);
ellipse(x+cos(a)*25, 150+sin(a)*25, 50, 50);
}
}
03.Java程式:箱子X軸轉動:
void setup(){
size(400,400,P3D);
}
void draw(){
background(128);
translate(width/2,height/2);
rotateX(radians(-mouseY));
box(200);
}
void setup(){
size(400,400,P3D);
}
04.Java程式:Z軸轉動:
void draw(){
background(128);
translate(width/2,height/2);
rotateZ(radians(mouseX));
ellipse(0,0,100,150);
}
05.Java程式:機械臂Z軸轉動:
void setup(){
size(400,400,P3D);
}
void draw(){
background(128);
translate(width/2,height/2);
pushMatrix();
translate(0,100);
box(50);
pushMatrix();
translate(0,0,-25);
rotateZ(radians(mouseX));
box(10,100,10);
popMatrix();
popMatrix();
}
06.Java程式:太陽系模型:
void setup() {
size(400, 400, P3D);
}
void draw() {
background(128);
translate(width/2,height/2);
sphere(50);
rotateY(radians(frameCount));
pushMatrix();
translate(150, 0);
rotateY(radians(frameCount));
sphere(30);
pushMatrix();
translate(50, 0);
rotateY(radians(frameCount));
sphere(10);
popMatrix();
popMatrix();
}
07.Java程式:地球自轉:
void setup() {
PShape earth;
size(400, 400, P3D);
earth = createShape(SPHERE, 100);
PImage img = loadImage("earth.jpg");
earth.setTexture(img);
}
void draw() {
background(0);
translate(width/2,height/2);
rotateY(radians(frameCount));
}
沒有留言:
張貼留言