Variable Faces

sketchfile

var eyeSize = 20;
var pupilSize = 10;
var faceWidth = 100;
var faceHeight = 150;
var earSize = 30;
var eyeColor = 0;
var hairHeight = 300;
var hairWidth = 200;
var mouth = 1;

function setup() {
    createCanvas(480, 640);
    background(0,200,0);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    background(150,50,25);
    fill(100);
    ellipse (width / 2, height / 2, hairWidth, hairHeight);
    fill(255,200,162);
    var earRX = (width / 2.1) + (faceWidth * .625);
    var earLX = (width / 1.9) - (faceWidth * .625);
    ellipse(earRX, height/2, earSize, earSize);
    ellipse(earLX, height /2, earSize, earSize);
    ellipse(width / 2, height / 2, faceWidth, faceHeight);
    fill(100)
    arc(width / 2, height / 2.1, hairWidth, hairHeight, PI, 0); //bangs
    fill(eyeColor);
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    noFill();
    strokeWeight(2);
    arc(width / 2, height / 1.9, faceWidth / 4, faceHeight / 4, 0, PI); //nose
    if (faceHeight <= 150){ // mouth 1
        arc(width / 2, height / 1.8 , faceWidth /3.5 * 2, faceHeight / 5 , 0, PI);
    } else if (faceHeight <= 170){ //mouth 2
        arc(width / 2, height / 1.7, faceWidth /3.5 * 2.2, faceHeight / 5 , PI, 0);
    } else { //mouth 3
        line(220, height / 1.7, 240, height / 1.7);
     }
    fill(eyeColor);
    ellipse(eyeLX, height / 2, eyeSize, eyeSize);
    ellipse(eyeRX, height / 2, eyeSize, eyeSize);
    fill(0);
    ellipse(eyeLX, height / 2, pupilSize, pupilSize);
    ellipse(eyeRX, height / 2, pupilSize, pupilSize);
     if(hairHeight <faceHeight){ //for no bald head
    hairHeight = 250};
}

function mousePressed() {
    faceWidth = random(75, 150);
    faceHeight = random(100, 200);
    eyeSize = random(10, 30);
    pupilSize = random(5, 15);
    earSize = random(20, 30);
    eyeColor = random(0, 255, 0, 255, 0, 255);
    hairWidth = random(150, 225);
    hairHeight = random(125, 225);
    mouth = random(0.1);
}
 

This project was a lot easier for me than the last. I however, spent a lot of time stuck on my if else statements due to a }. Regardless, I made a changing face with eyes that turn different shades of grey and has different smiles. My person kinda looks like an old lady to me.

Leave a Reply