逐漸進步讓球可以自己變大
接下來讓答案的球變顏色
而且滑鼠移過去的球要可以變顏色
接下來修改成滑鼠如果按到答案 那球就換地方
最後換個顏色 大功告成~
整個代碼:
void setup()
{
size(300,500);
colorMode(HSB,256);
}
int ansX=1,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,243);
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;
}






沒有留言:
張貼留言