Robot face1;
Robot face2;
Robot face3;
void setup() {
size(640, 480);
smooth();
rectMode(CENTER);
face1 = new Robot(random(width), random(height), random(0.1, 1), random(10, 255));
face2 = new Robot(random(width), random(height), random(0.1, 1), random(10, 255));
face3 = new Robot(random(width), random(height), random(0.1, 1), random(10, 255));
}
void draw() {
background(255);
face1.moveArm();
face1.moveEye();
face1.move();
face1.display();
face2.moveArm();
face2.moveEye();
face2.move();
face2.display();
face3.moveArm();
face3.moveEye();
face3.move();
face3.display();
}
class Robot {
float x;
float y;
float scalar;
float armLength = 291;
float armMovement = random(1, 60);
float eyeSize = 10;
float eyeMovement = random(1, 20);
float speed = random(1, 4);
float fillColor;
Robot(float x_in, float y_in, float scalar_in, float fillColor_in) {
x = x_in;
y = y_in;
scalar = scalar_in;
fillColor = fillColor_in;
}
void move() {
x += random(-speed, speed);
x = constrain(x, 0, width);
y += random(-speed, speed);
y = constrain(y, 0, height);
}
void display() {
pushMatrix();
translate(x, y);
scale(scalar);
stroke(fillColor);
strokeWeight(25);
line(192, 231, 192, armLength); //arms
line(41, 231, 41, armLength);
line(139, 312, 139, 351); //legs
line(95, 312, 95, 351);
strokeWeight(3);
line(141, 171, 152, 151); //antennas
line(93, 171, 82, 151);
noStroke();
fill(fillColor);
arc(117, 219, 115, 115, PI, PI * 2); //body
rect(117, 275, 115, 100);
fill(255);
ellipse(143, 189, eyeSize, eyeSize);
ellipse(91, 189, eyeSize, eyeSize);
popMatrix();
}
void moveArm() {
armLength += armMovement;
if(armLength < 200 || armLength > 300) {
armMovement = - armMovement;
}
}
void moveEye() {
eyeSize += eyeMovement;
if(eyeSize < 5 || eyeSize > 20) {
eyeMovement = - eyeMovement;
}
}
}