//Simple beginning template for variable face
var eyeSize = 40;
var faceWidth = 400;
var faceHeight = 400;
var noseWidth = 3;
var mouth = 1;
var hair = 1;
var body = 100;
function setup() {
createCanvas(640, 480);
}
function draw() {
background (250);
fill (239, 230, 131); // hands fill
ellipse (200, 320, 50, 50); // right hand
ellipse (440, 320, 50, 50); // left hand
fill (255, 153, 52); // body fill
ellipse (width / 2, height / 2 + 100, body, body + 50); // body
fill (107, 183, 216);
ellipse(width / 2, height / 2, faceWidth, faceHeight); // face shape
fill ( 0, 0, 0 );
stroke (254, 211, 66);
strokeWeight (2);
var eyeLX = (width / 2 - faceWidth * 0.25);
var eyeRX = (width / 2 + faceWidth * 0.25);
ellipse(eyeLX, height / 2, eyeSize, eyeSize);
ellipse(eyeRX, height / 2, eyeSize, eyeSize);
stroke ( 0, 0, 0);
strokeWeight(1);
fill( 228, 129, 203 );
if (mouth < 0.33) { // rect mouth
rect ( width / 2 - 10, height / 2 + 30, 40, 20 );
} else if ( mouth < 0.66 ) { // line mouth
line (( width / 2 - 20 ),( height / 2 +30 ), ( width / 2 + 30 ),( height / 2 +40));
} else if ( mouth < 1 ) { // ellipse mouth
ellipse ( width / 2, height / 2 + 30, faceWidth / 2, faceHeight / 8);
}
fill (49, 50, 52);
strokeWeight (1);
if (noseWidth <= 1) { // nose 1
triangle (width / 2, height / 2, width / 2 + 10, height / 2, width / 2 + 5, height / 2 + 10);
} else if (noseWidth <=2) { // nose 2
triangle (width / 2 - 5, height / 2 + 3, width / 2 + 8, height / 2 + 1, width / 2 + 3, height / 2 + 16);
} else if (noseWidth <=3) { // nose 3
triangle (width / 2 - 5, height / 2 +5, width / 2 + 6, height / 2 + 2, width / 2 + 15, height / 2 + 7);
}
}
function mousePressed() {
// when the user clicks, these variables are reassigned
// to random values within specified ranges. For example,
// 'faceWidth' gets a random value between 75 and 150.
faceWidth = random(75, 350);
faceHeight = random(100, 250);
eyeSize = random(10, 30);
mouth = random(0,1);
noseWidth = random(0,3);
body = random (200, 250);
}
I struggled with understanding how to manipulate variables in a randomized order but I had fun writing this code as it was satisfying to see it actually work at the end.