PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
void setup()
{
size(416,644);
imgBG=loadImage("1.jpg"); ←把圖片拉進processing //size要相同
}
void draw()
{
background(imgBG);
circle(x[0],y[0],20);
}
void mousePressed()
{
x[0]=mouseX;
y[0]=mouseY;
}

多顆圓形
PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
size(416,644);
imgBG=loadImage("1.jpg");
}
void draw()
{
background(imgBG);
for(int i=0; i<5; i++) ←五顆以內
{
circle(x[i],y[i],20);
}
}
void mousePressed()
{
if(n>=5) return; ←萬一超過五顆不會當掉
x[n]=mouseX;
y[n]=mouseY;
n++; ←for迴圈才放**i
}

多顆循環
PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
size(416,644);
imgBG=loadImage("1.jpg");
}
void draw()
{
background(imgBG);
for(int i=0; i<5; i++)
{
circle(x[i],y[i],20);
}
}
void mousePressed()
{
x[n]=mouseX;
y[n]=mouseY;
n=(n+1)%5; ←更改成可回收循環 //原先if(n>=5) return; 要刪掉
}

讓子彈飛
PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int n=0;
void setup()
{
size(416,644);
imgBG=loadImage("1.jpg");
}
void draw()
{
background(imgBG);
for(int i=0; i<5; i++)
{
circle(x[i],y[i],20);
y[i]--; ←新增 //y軸向上
}
}
void mousePressed()
{
x[n]=mouseX;
y[n]=mouseY;
n=(n+1)%5;
}
For迴圈搭配陣列
int[]a={0,0,1,0}; ←數字1呈現紅色
size(400,100);
for(int i=0;i<4; i++)
{
if(a[i]==1) fill(255,0,0);
else fill(128);
rect(i*100,0,100,100);
}

PImage imgBG;
int []x={0,0,0,0,0};
int []y={0,0,0,0,0};
int []r={5,5,5,5,5};
int n=0;
void setup()
{
size(416,644);
imgBG=loadImage("1.jpg");
}
void draw()
{
background(imgBG);
for(int i=0; i<5; i++)
{
circle(x[i],y[i],r[i]);
if(mousePressed) r[now]++;
y[i]--;
}
}
int now=0;
void mousePressed()
{
x[n]=mouseX;
y[n]=mouseY;
r[n]=5;
now=n;
n=(n+1)%5;
}
沒有留言:
張貼留言