求解答,processing中,自己定义一个类,可不可以返回一个值??
processing吧
全部回复
仅看楼主
level 7
暖冰WI 楼主
如题
2014年11月01日 11点11分 1
level 7
暖冰WI 楼主
int n=10;
Cricle[] cricle=new Cricle[n];
void setup(){
size(700,500);
smooth();
for(int i=0;i<n;i++){
cricle[i]=new Cricle(random(-5,5),random(-5,5),int(random(50,100)));
}
}
void draw(){
background(255);
for(int i=0;i<n;i++){
cricle[i].move();
cricle[i].display();
}
}
class Cricle{
float x,y;
float sy;
float sx;
int r;
Cricle(float tsx,float tsy,int tr){
sx=tsx;
sy=tsy;
r=tr;
}
void move(){
if((x<0)||(x>width)){
sx*=-1;
}
if((y<0)||(y>height)){
sy*=-1;
}
x+=sx;
y+=sy;
}
void display(){
fill(0,191,255);
ellipse(x,y,r,r);
}
}
2014年11月02日 13点11分 3
1