ellipse(75,200+75+150,100,150);
(圓心x軸,圓心y軸,圓長,圓寬)
3*3個圓
加入for迴圈
size(300,500);
for(int y=0;y<3;y++)
{
for(int x=0;x<3;x++)
{
ellipse(50+x*100,200+50+y*100,100,100);
}
}
讓球慢慢變小,變多
{
size(300,500);
}
int ansX=2,ansY=2;
int n=3,RR=0;
void draw()
{
background(0);
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
if(x==ansX && y==ansY)fill(128);
else fill(255);
if(dist(mouseX,mouseY,w+x*R,200+w+y*R)<w)fill(255,0,0);
#這行表示游標若小於圓半徑則改變顏色
ellipse(w+x*R,200+w+y*R,RR,RR);
}
}
if(RR<R)RR+=R/30;
}
點選不一樣的圓便會跳至其他圓
加入變色系統
void setup(){
size(300,500);
colorMode(HSB,256); #變色系統
}
int ansX=2,ansY=2;
int n=3,RR=0;
int H=0;
void draw()
{
background(0);
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
if(x==ansX && y==ansY)fill(H-10,243,234);
else fill(H,255,255);
if(dist(mouseX,mouseY,w+x*R,200+w+y*R)<w)
{
if(mousePressed && x==ansX && y==ansY)
{
ansX=int(random(n));
ansY=int(random(n));
H+=20;
if(H>256)H=0;
}
}
ellipse(w+x*R,200+w+y*R,RR,RR);
}
}
if(RR<R)RR+=R/30;
}







沒有留言:
張貼留言