1.1
float k=0.001;
float[] r=new float[10];
float[] g=new float[10];
float[] b=new float[10];
void flower()
{
pushMatrix();
for(int i=0;i<10;i++){
rotate(PI/5);
fill(r[i],g[i],b[i]);
ellipse(40,0,80,25);
fill(255,255,0);
ellipse(0,0,25,25);
}
popMatrix();
}
void setup()
{
size(720,720);
background(255);
for(int i=0;i<10;i++){
r[i]=random(0,255);
g[i]=random(0,255);
b[i]=random(0,255);
}
}
void draw()
{
scale(1.2,1.2);
background(255);
translate(300,300);
pushMatrix();
rotate(k);
k+=0.01;
flower();
popMatrix();
}
2.2
鍵盤上下,可調整時鐘速度!
滑鼠左鍵震動畫面。
float k=0.001;
float[] r=new float[10];
float[] g=new float[10];
float[] b=new float[10];
float h=0,m=0,s=0;
int ox,oy;
PFont myFont;
float speed=0.001;
float sizea,sizeb;
void keyPressed(){
if(key == CODED){
if(keyCode == UP) speed+=0.002;
else if(keyCode == DOWN) speed-=0.002;
}
}
int count=0;
void mouseClicked()
{
sizea=sizeb=1.1;
count=0;
}
void flower()
{
pushMatrix();
for(int i=0;i<10;i++){
rotate(PI/5);
fill(r[i],g[i],b[i]);
ellipse(40,0,80,25);
fill(255,255,0);
ellipse(0,0,25,25);
}
popMatrix();
}
void clock()
{
pushMatrix();
translate(-9,9);
for(int i=1;i<13;i++)
text(i, 250*cos(PI/6*(i-3)),250*sin(PI/6*(i-3)));
popMatrix();
}
void setup()
{
sizea=sizeb=1;
myFont = createFont("FFScala", 32);
textFont(myFont);
size(600,600);
background(255);
for(int i=0;i<10;i++){
r[i]=random(0,255);
g[i]=random(0,255);
b[i]=random(0,255);
}
}
void draw()
{
background(255);
translate(300,300);
scale(sizea,sizeb);
//Board
stroke(0);
fill(205,174,201);
strokeWeight(10);
ellipse(0,0,600,600);
strokeWeight(1);
//Flower
pushMatrix();
rotate(k);
k+=0.01;
flower();
popMatrix();
//Time
clock();
//Hour , minute and second
strokeWeight(5);
stroke(0);
line(0,0,120*cos(PI/6*(h-3)),120*sin(PI/6*(h-3)));
h+=speed;
stroke(128,0,0);
line(0,0,180*cos(PI/6*(m-3)),180*sin(PI/6*(m-3)));
m+=speed*12;
stroke(255,0,0);
line(0,0,240*cos(PI/6*(s-3)),240*sin(PI/6*(s-3)));
s+=speed*144;
count++;
if(count == 2){
sizea=sizeb=1;
count=0;
}
save("C:/sv.jpg");
}
2.3
想做像是以前外面大型音樂遊戲機台的模式,有一個踏板,以及六個按鍵。
而在這次作業希望能以六個鍵盤按鍵取代。
方式為游標由上向下落,直到指定位置按下對應件即可得分。
100
回覆刪除