xxxxxxxxxx
113
// Start Minion class
// A MINION
class Minion {
constructor(xpos, ypos, numh, numeyes, shade) {
this.x = xpos;
this.y = ypos;
this.hair = numh;
this.eye = 25;
this.eyeballs = numeyes;
this.skin = shade;
this.wface = 50 + random(20);
this.hface = 100 - random(20);
}
display(xbubble, ybubble) {
// body
stroke(255, 255, 0);
noStroke();
fill(this.skin, this.skin, 0);
rect(this.x, this.y, this.wface, this.hface, 20)
// eye(s)
let dx = map(xbubble - this.x, -width, width, 3 - this.eye / 2, this.eye / 2 - 3);
let dy = map(ybubble - (this.y - 20), -height, height, 3 - this.eye / 2, this.eye / 2 - 3);
if (this.eyeballs <= 1) {
this.eye = 25;
this.drawEye(this.x, this.y-20, dx,dy);
} else {
this.eye = 20;
this.drawEye(this.x + 11, this.y - 20, dx, dy);
this.drawEye(this.x - 11, this.y - 20, dx, dy);
}
// overalls
fill(125, 125, 255);
rect(this.x, this.y + 30, this.wface, 40, 0, 0, 20, 20);
fill(this.skin, this.skin, 0);
rect(this.x, this.y + 20, this.wface, 20);
fill(125, 125, 255);
rect(this.x, this.y + 24, 36, 16);
strokeWeight(1);
stroke(100,100,210);
rect(this.x, this.y+30, 20, 12, 0, 0, 6, 6);
strokeWeight(4);
stroke(125, 125, 255);
line(this.x + 18, this.y + 16, this.x + this.wface/2, this.y + 8);
line(this.x - 18, this.y + 16, this.x - this.wface/2, this.y + 8);
// mouth
stroke(20);
strokeWeight(1);
noFill();
if (dist(this.x, this.y, xbubble, ybubble) < 80) {
fill(0);
arc(this.x, this.y, 20, 15, 0, PI, CHORD);
} else
arc(this.x, this.y, 20, 15, PI / 8, PI - PI / 8);
// hair
noFill();
for (let i = 0; i < this.hair; i++) {
arc(this.x + 10, this.y - 50 + (100-this.hface)/2, 20, 30 - 5 * i, PI, 3 * PI / 2 + i * PI / 5);
}
}
drawEye(x,y, dx, dy) {
stroke(0);
strokeWeight(0);
fill(255);
ellipse(x, y, this.eye);
fill(0);
ellipse(x + dx, y + dy, 8);
fill(50, 150, 0);
ellipse(x + dx, y + dy, 6);
fill(0);
ellipse(x + dx, y + dy, 3);
}
}
// Minion Class is over.
/**********************************************************/
// Start Bubble class
class Bubble {
// a place to store all the properties of the bubble
// computer must see a constructor!
constructor(xpos, ypos, diameter) {
this.x = xpos;
this.y = ypos;
this.d = diameter;
this.xdir = 1;
this.ydir = 1;
}
// writing functions/method does not need the word function
display() {
//function goal: draw my bubble
fill(this.x, 0, this.y, 40);
stroke(255);
strokeWeight(2);
ellipse(this.x, this.y, this.d);
}
move() {
if (this.x > width || this.x < 0) this.xdir *= -1;
if (this.y > height || this.y < 0) this.ydir *= -1;
this.x += this.xdir * random(0, 3);
this.y += this.ydir * random(0, 2);
}
}
// Bubble class is over.