xxxxxxxxxx
class Bug {
float x;
float y;
float w;
float h;
float xSpeed;
float ySpeed;
float easing = random (0.02,0.09);
color bodycolor;
color eyecolor;
color wingcolor;
Bug () {
x = random (width);
y = random (height);
w = 50;
h = 60;
xSpeed = random (2,6);
ySpeed = random (2,6);
bodycolor = color (#ffb732);
eyecolor = color (#332100);
wingcolor = color (#f7eec3);
}
void move () {
y += ySpeed;
x += xSpeed;
if ((x > width) || (x < 0 )) {
xSpeed = xSpeed *-1;
}
if ((y > height) || (y < 0)) {
ySpeed = ySpeed *-1;
}
}
void display () {
noStroke();
fill(bodycolor);
ellipse(x, y, w, h);
ellipse(x+30,y, w-20, w-20);
fill(eyecolor);
ellipse(x+35,y-10, w-40,w-40);
ellipse(x+35,y+10, w-40,w-40);
fill(wingcolor);
ellipse(x-5,y-25,w-10,w-10);
ellipse(x-5,y+25,w-10,w-10);
float targetX = mouseX;
float dx = targetX-x;
x += dx * easing;
float targetY = mouseY;
float dy = targetY-y;
y += dy * easing;
}
}