首先,在Processing中先讓隕石出現
int x=0,y=0; ///先設定隕石座標為0,0
void setup() ///設定setup
{
size(300,400); ///畫布大小300X400
}
void draw() ///一秒畫60次
{
background(255); ///會有殘影,所以每次都將背景先塗白
circle(x,y,10); ///circle就是畫隕石,大小為10
y++; ///往下掉就是Y值++
if(mousePressed){ ///如果按MOUSE,就在點擊的地方放新隕石
x=mouseX;
y=mouseY;
}
}
再來,如果想要同時有30顆隕石
int []x={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; ///陣列
int []y={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; ///陣列,隕石的座標
int n=0; ///0顆隕石
void setup(){ ///設定setup
size(300,400);
}
void draw(){
background(255);
for(int i=0;i<n;i++)
{
circle(x[i],y[i],20);
y[i]+=3;
if(y[i]>=400-10) y[i]=400-10; ///剪掉圓的半徑
}
}
void mousePressed() ///如果mouse點擊
{
if(n<30)
{
x[n]=mouseX; ///就在點擊的地方放隕石
y[n]=mouseY;
n++;
}
}
就像降
沒有留言:
張貼留言