EYE[]hieye=new EYE[100]; //定义对象
void setup() {
size(600, 300);
smooth();
colorMode(HSB, 360, 100, 100);
for (int i=0;i<hieye.length;i++) {
hieye=new EYE(random(30,width-30),random(height),random(5,30),color(random(360),100,100));
}
}
void draw() {
background(255);
for (int i=0;i<hieye.length;i++) {
hieye.display();
hieye.move();
}
}
class EYE {
float x;
float y;
float d;
float speed;
float c;
EYE(float x1, float y1, float d1, float c1) {
float x=x1;
float y=y1;
float speed=2;
float d=d1;
float c=c1;
}
void display() {
stroke(0);
strokeWeight(d/15);
fill(360);
ellipse(x, y, d*2, d);
strokeWeight(d/20);
fill(c);
ellipse(x, y, d, d);
fill(0);
noStroke();
ellipse(x, y, d/3, d/3);
}
void move() {
x=x+speed;
if (x>width-d||x<d) {
speed=-speed;
}
}
}