// All Examples Written by Casey Reas and Ben Fry
// unless otherwise stated.
Eye[] e = new Eye[3]; // największą zmianą jest użycie tablicy zamiast szeregu zmiennych
void setup(){
size(500, 480);
smooth();
noStroke();
e[0] = new Eye( 400, 110, 80, #3333FF );
e[1] = new Eye( 150, 150, 120, #00FF66 );
e[2] = new Eye( 250, 300, 200, #990000 );
}
void draw(){
background( 0 );
for( int i = 0; i < e.length; i ++ ){ // co znacząco skraca kod
e[i].update( mouseX, mouseY );
e[i].display();
}
}
class Eye {
int ex, ey;
int size;
float angle = 0.0;
color col; // dodane zostały również indywidualne kolory oczu
Eye(int x, int y, int s, color c ) {
ex = x;
ey = y;
size = s;
col = c;
}
void update(int mx, int my) {
angle = atan2(my-ey, mx-ex);
}
void display() {
pushMatrix();
translate(ex, ey);
fill( 255 );
ellipse(0, 0, size, size);
rotate(angle);
fill( col );
ellipse(size/4, 0, size/2, size/2);
popMatrix();
}
}