如何做出很多的 Java 視窗, 而且每一個都能有 void setup()
及 void draw()來做動作
import java.awt.Frame;
PFrame f;
secondApplet s;
void setup() {
size(320, 240);
PFrame f = new PFrame();
}
void draw() {
background(255,0,0);
fill(255);
rect(10,10,frameCount%100,10);
s.background(0, 0, 255);
s.fill(100);
s.rect(10,20,frameCount%120,10);
s.redraw();
}
public class PFrame extends Frame {
public PFrame() {
setBounds(100,100,400,300);
s = new secondApplet();
add(s);
s.init();
show();
}
}
public class secondApplet extends PApplet {
public void setup() {
size(400, 300);
noLoop();
}
public void draw() {
}
}
會動的可愛眼睛
void setup() {
size(120,100); //窗口大小
}
void draw() {
float t=frameCount/180.0*PI;
background(0);
fill(255);//眼白
ellipse(40,50,33,33); //眼白的圓
ellipse(120-40,50,33,33);
fill(0); //眼珠全黑
ellipse(40+15*cos(t),50+15*sin(t),5,5); //眼珠旋轉
ellipse(120-40+15*cos(t),50+15*sin(t),5,5);
}
眼珠跟隨滑鼠
void setup() {
size(120,100); //窗口大小
}
void draw() {
// float t=frameCount/180.0*PI;
background(0);
fill(255);//眼白
ellipse(40,50,33,33); //眼白的圓
ellipse(120-40,50,33,33);
fill(0); //眼珠全黑
float t=atan2(mouseY-50,mouseX-45);
ellipse(40+15*cos(t),50+15*sin(t),5,5); //眼珠旋轉
ellipse(120-40+15*cos(t),50+15*sin(t),5,5);
沒有留言:
張貼留言