01.Java程式:立方體:
void setup(){
size(400,400,P3D);
}
void draw(){
background(128);
translate(mouseX,mouseY);
rotateY(radians(frameCount));
box(200);
}
02.Java程式:2D坐標系:
size(400,400);
stroke(255,0,0);
strokeWeight(8);
point(200,200);
line(200,0,400,100);
rect(50,50,100,100);
fill(255,255,0);
ellipse(300,200,50,80);
03.Java程式:各種矩形:
size(400,400);
rect(50,50,100,100);
rect(50,200,100,100,20);
rect(200,50,100,100,10,20,30,40);
04.Java程式:畫筆換顏色:
void setup() {
size(400, 400);
}
void draw() {
fill(255,0,0);
rect(0, 0, 50, 50);
fill(255,255,0);
rect(0, 50, 50, 50);
fill(0,255,0);
rect(0, 100, 50, 50);
fill(0,0,255);
rect(0, 150, 50, 50);
if(mousePressed) line(mouseX,mouseY,pmouseX,pmouseY);
}
void mousePressed() {
if (mouseX<50) {
if (mouseY<50) stroke(255, 0, 0);
else if (mouseY<100) stroke(255, 255, 0);
else if (mouseY<150) stroke(0, 255, 0);
else if (mouseY<200) stroke(0, 0, 255);
}
}
04.Java程式:向量移動:
void setup(){
size(400,400);
}
float startX =10,startY = 10;
float stopX =390,stopY = 290;
void draw(){
ellipse(startX,startY,10,10);
ellipse(stopX,stopY,10,10);
float midX = lerp(startX, stopX,frameCount / 200.0);
float midY = lerp(startY, stopY,frameCount / 200.0);
ellipse(midX,midY,10,10);
}
05.Java程式:費氏函數向量移動:
void setup() {
size(400, 400);
}
void draw() {
size(400, 400);
int x1 = 340, x2 = 40, x3 = 360, x4 = 60;
int y1 = 80, y2 = 40, y3 = 360, y4 = 320;
line(x1, y1, x2, y2);
line(x3, y3, x4, y4);
bezier(x1, y1, x2, y2, x3, y3, x4, y4);
float t = frameCount / 200.0;
float t2 = 1 -t;
float x = x1*t2*t2*t2+3*x2*t*t2*t2+3*x3*t*t*t2+x4*t*t*t;
float y = y1*t2*t2*t2+3*y2*t*t2*t2+3*y3*t*t*t2+y4*t*t*t;
ellipse(x, y, 10, 10);
}
06.Java程式:立體星空:
float []x=new float[5000];
float []y=new float[5000];
float []z=new float[5000];
void setup() {
size(400, 400, P3D);
for (int i=0; i<1000; i++) {
x[i]=random(400);
y[i]=random(400);
z[i]=random(-400,400);
}
}
void draw(){
background(0);
stroke(255);
translate(0,0,mouseY);
for(int i=0;i<5000;i++){
point(x[i],y[i],z[i]);
}
}
07.Java程式:立體球:
void setup(){
size(400,400,P3D);
}
void draw(){
background(128);
lights();
translate(mouseX,mouseY);
rotateY(radians(frameCount));
sphere(200);
}
08.Java程式:立體球+矩陣:
void setup() {
size(400, 400, P3D);
}
void draw() {
background(128);
lights();
pushMatrix();
translate(100,100);
rotateY(radians(frameCount));
sphere(100);
popMatrix();
pushMatrix();
translate(300, 100);
rotateY(radians(frameCount));
sphere(100);
沒有留言:
張貼留言