xxxxxxxxxx
63
class Face {
constructor(x, y) {
this.x = x;
this.y = y;
this.faceSize = size-size/5;
// Eyes
let xeye = map(random(15, 20), 0, 20, 0, 20/100*this.faceSize);
let yeye = map(random(15, 20), 0, 20, 0, 20/100*this.faceSize);
this.leftEye = createVector(-xeye, -yeye);
this.rightEye = createVector(xeye, -yeye);
this.eyeSize = map(random(20, 25), 0, 25, 0, 25/100*this.faceSize);
this.pupilSize = map(random(10, 15), 0, 15, 0, 15/100*this.faceSize);
// Nose
this.xnose = map(random(10, 15), 0, 15, 0, 15/100*this.faceSize);
this.ynose = map(random(30, 40), 0, 40, 0, 40/100*this.faceSize);
// Mouth
let xmouth = map(random(20, 40), 0, 40, 0, 40/100*this.faceSize);
let ymouth = map(random(10, 20), 0, 20, 0, 20/100*this.faceSize);
let xanchor = map(random(30, 35), 0, 35, 0, 35/100*this.faceSize);
let yanchor = map(random(40, 50), 0, 50, 0, 50/100*this.faceSize);
this.pt1 = createVector(-xmouth, ymouth);
this.pt2 = createVector(-xanchor, yanchor);
this.pt3 = createVector(xanchor, yanchor);
this.pt4 = createVector(xmouth, ymouth);
// Color
this.randomColor = floor(random(7));
}
drawFace() {
push();
translate(this.x, this.y);
// Face
noStroke();
let colors = ["#abcd5e", "#14976b", "#2b67af", "#62b6de", "#f589a3", "#ef562f", "#fc8405", "#f9d531"];
fill(colors[this.randomColor]);
ellipse(0, 0, this.faceSize, this.faceSize);
// Eyes
fill(255);
ellipse(this.leftEye.x, this.leftEye.y, this.eyeSize, this.eyeSize);
ellipse(this.rightEye.x, this.rightEye.y, this.eyeSize, this.eyeSize);
fill(0);
ellipse(this.leftEye.x, this.leftEye.y, this.pupilSize, this.pupilSize);
ellipse(this.rightEye.x, this.rightEye.y, this.pupilSize, this.pupilSize);
// Nose
rect(0, 0, this.xnose, this.ynose, 20);
// Mouth
noFill();
stroke(0);
bezier(this.pt1.x, this.pt1.y, this.pt2.x, this.pt2.y, this.pt3.x, this.pt3.y, this.pt4.x, this.pt4.y);
pop();
}
}