第五週課程:酷東西
Week05:Cool Example
第一節課(多視窗)
1. 多視窗
參考網址
https://forum.processing.org/one/topic/multiple-windows-2-4-2011.html
但是因為是舊版的,所以要加入import java.awt.Frame;
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 secondApplet extends PApplet
{
{
public void setup()
{
{
size(400, 300);
noLoop();
}
public class PFrame extends Frame
{
{
public PFrame()
{
{
setBounds(100,100,400,300);
s = new secondApplet();
add(s);
s.init();
show();
}
}
第二節課(轉動的眼珠)
1. 轉動眼珠
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);
}
第三節課(酷範例)
1. 眼珠跟著滑鼠
void setup()
{
{
size(120,100);
}
void draw()
{
{
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);
t=atan2(mouseY-50,mouseX-(120-40));//滑鼠作標
ellipse(120-40+15*cos(t),50+15*sin(t),5,5);
}
2. 雙螺旋
void setup()
{
size(800,800);
}
void draw()
{
background(255);
float t=frameCount/100.0;
for(float f=0;f<PI;f+=0.1)//畫方塊
{
rect(200+150*cos(f+t),f*100,30,30);
rect(200+150*cos(f+t+PI),f*100,30,30);
}
}
沒有留言:
張貼留言