Judy Li-Project-02-Variable-Face

judyli:Face Project 02

/*
Judy Li
Section A
judyli@andrew.cmu.edu
Project-02
*/

var eyeSize = 30;
var ballSize = 8;
var ellfaceWidth = 100;
var ellfaceHeight = 150;
var recfaceWidth = 100;
var recfaceHeight = 150;
var noseSize = 5;
var mouthWidth = 10;
var mouthHeight = 5;
var hatWidth = 200;
var hatHeight = 15;
 
function setup() {
    createCanvas(640, 480);
    stroke(0);
    strokeWeight(1.5);
    r = random(255);
    g = random(255);
    b = random(255);
}

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.
    ellfaceWidth = random(125, 250);
    ellfaceHeight = random(125, 250);
    eyeSize = random(10, 30);
    recfaceWidth = random(125, 250);
    recfaceHeight = random(125, 250);
    noseSize = random(1, 5);
    mouthWidth = random(10, 50);
    mouthHeight = random(1, 10);
    recnoseWidth = random(10, 50);
    recnoseHeight = random(10, 50);
    hatWidth = random(250,300);
    hatHeight = random(5,25);
    fill(r,g,b,);
    r = random(255);
    g = random(255);
    b = random(255);
}

function draw() {
    scale(7/8);
    background(218,175,32);
    if (mouseX < (width / 2)) {
        //Round Head
        ellipse(width / 4, height / 2, ellfaceWidth,  ellfaceHeight);
        var eyeLX = width / 4 - ellfaceWidth * 0.25;
        var eyeRX = width / 4 + ellfaceWidth * 0.25;
        var ballLX = width/4 - ellfaceWidth * 0.25;
        var ballRX = width/4 + ellfaceWidth * 0.25;
        //Glasses
        push();
        strokeWeight(5);
        stroke(255);
        ellipse(eyeLX, height / 2, eyeSize/2, eyeSize/2);
        ellipse(eyeRX, height / 2, eyeSize/2, eyeSize/2);
        pop();
        //Eyes
        strokeWeight(5);
        ellipse(ballLX, height / 2, ballSize/4, ballSize/4);
        ellipse(ballRX, height / 2, ballSize/4, ballSize/4);
        //Nose
        push();
        stroke(0);
        strokeWeight(5);
        ellipse(width / 4, (height / 2)+20, noseSize, noseSize);
        //Mouth
        strokeWeight(10);
        ellipse(width / 4, (height / 2)+50, mouthWidth, mouthHeight);
        pop();
    }

    if (mouseX >(width / 2)) {
        //Rectangular Head
        rect(3*(width / 5), (height / 3), recfaceWidth,  recfaceHeight);
        var eyeLX = (3*(width / 5)) + 1.75*(recfaceWidth * 0.2);
        var eyeRX = (3*(width / 5)) + 3.25*(recfaceWidth * 0.2);
        var ballLX = (3*(width / 5)) + 1.75*(recfaceWidth * 0.2);
        var ballRX = (3*(width / 5)) + 3.25*(recfaceWidth * 0.2);
        //Glasses
        push();
        strokeWeight(5);
        stroke(255);
        ellipse(eyeLX, (height / 3)+50, eyeSize, eyeSize);
        ellipse(eyeRX, (height / 3)+50, eyeSize, eyeSize);
        pop();
        //Eyes
        strokeWeight(5);
        ellipse(ballLX, (height / 3)+50, ballSize/2, ballSize/2);
        ellipse(ballRX, (height / 3)+50, ballSize/2, ballSize/2);
        //Nose
        push();
        stroke(255);
        strokeWeight(5);
        ellipse(3*(width / 5) + (recfaceWidth/2), (height / 2), noseSize, noseSize);
        //Mouth
        strokeWeight(10);
        ellipse(3*(width / 5) + (recfaceWidth/2), (height / 2)+30, mouthWidth, mouthHeight);
        pop();
    }
}
         

This project was a challenging one at first. I think I had some trouble with some overlaps in terms of what was supposed to show up first, second, and etc. But, I enjoyed writing up the codes for this project because it was fun and I was satisfied with my end results.

Leave a Reply