size(300,500);
ellipse(75,200+75,150,150);
ellipse(75+150,200+75,150,150);

size(300,500);
int n=3; →因為寬度是300,有三個球去分
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
ellipse(w+x*R,200+w+y*R, R,R);
}
}

size(300,500);
int n=4; →因為寬度是300,有四個球去分
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
ellipse(w+x*R,200+w+y*R, R,R);
}
}

size(300,500);
int n=4;
int R=300/n,w=R/2;
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
ellipse(w+x*R,200+w+y*R, RR,RR);
}
}
if(RR<R)RR++ →如果沒超過範圍,++//從小變到大
}
}

int n=5;
int R=300/n,w=R/2,RR=0;
void draw()
{
background(0);
for(int y=0;y<n;y++)
{
for(int x=0;x<n;x++)
{
ellipse(w+x*R,200+w+y*R, RR,RR);
}
}
if(RR<R)RR+=R/10; →為了讓速度一致改成RR+=R/10變成很快
else
{
n++; →下一個數目
RR=0; →從小開始長
}
}

void setup()
{
size(300,500);
}
int ansX=1,ansY=2; →答案
int n=5,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); →mouse選中誰就變色
ellipse(w+x*R,200+w+y*R, RR,RR);
}
}
if(RR<R)RR+=R/30;
}

void setup()
{
size(300,500);
}
int ansX=1,ansY=2;
int n=5,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) →mouse選中誰
{
if(x==ansX &&y==ansY) →並且是答案
{
ansX=int (random(n));
ansY=int (random(n));
}
}
ellipse(w+x*R,200+w+y*R, RR,RR);
}
}
if(RR<R)RR+=R/30;
}
//mouse只是碰到就換格

void setup()
{
size(300,500);
}
int ansX=1,ansY=2;
int n=5,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)
{
if(mousePressed && x==ansX &&y==ansY) →mouse點選到正確答案
{
ansX=int (random(n));
ansY=int (random(n));
}
}
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=1,ansY=2;
int n=5,RR=0;
int H=0; →改色彩系統//Hue色調色相
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;
}

沒有留言:
張貼留言