Tanvi Harkare – Project 02 – Variable Face

tanvi_facevariable

/* Tanvi Harkare
Section B
tharkare@andrew.cmu.edu
Project-02-Face Variables */

var eyeSize = 20;
var faceWidth = 100;
var faceHeight = 150;
var eyeColorR = 150
var eyeColorG = 250
var eyeColorB = 5;
var mouthWidth = 50;
var mouthHeight = 30; 
var mouthY = 340; 
var browHeight = 300;
var eyeHeight = 320;

function setup() {  
    createCanvas(480, 640); 
}

function draw() {
    background(150);

    //hair
    stroke(0);
    strokeWeight(150);
    line(width/2, height/2 - 20, width/2, height - 225);

    //face
    fill(255, 220, 177);
    noStroke(); 
    ellipse(width / 2, height / 2, faceWidth,  faceHeight);

    //eyes
    noStroke();
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    fill(255);
    ellipse(eyeLX, eyeHeight, eyeSize, eyeSize); //left eye
    ellipse(eyeRX, eyeHeight, eyeSize, eyeSize); //right eye
    //pupils
    fill(eyeColorR, eyeColorG, eyeColorB);
    ellipse(eyeLX, eyeHeight, eyeSize/2, eyeSize/2); //left pupil
    ellipse(eyeRX, eyeHeight, eyeSize/2, eyeSize/2); //right pupil

    //mouth
    noFill();
    strokeWeight(2);
    stroke(100, 75, 80);
    arc(240, mouthY, mouthWidth, mouthHeight, 0, 3.14, OPEN);

    //eyebrows
    strokeWeight(2);
    stroke(0);
    line(eyeLX - 10, eyeHeight - 10 - eyeSize, eyeLX + 10, eyeHeight - 10 - eyeSize);
    line(eyeRX - 10, eyeHeight - 10 - eyeSize, eyeRX + 10, eyeHeight - 10 - eyeSize);

    //nose
    noStroke();
    fill(198, 171, 137);
    ellipse(width/2, height/2 + eyeSize, 10, 8);
}

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(100, 130);
    faceHeight = random(110, 160);
    eyeSize = random(10, 20);
    eyeColorR = random(0, 255);
    eyeColorG = random(0, 255);
    eyeColorB = random(0, 255);
    mouthWidth = random(30, 60);
    mouthHeight = random(20, 40);
    mouthY = random(335, 350);
    browHeight = random(290, 305);
    eyeHeight = random(315, 325);
}

For this project, I created a face from simple shapes such as ellipses, arcs, and lines. My favorite part of the project was coming up with different ways to create a unique face with colors, size, and position on the face. At first I had a difficult time dealing with facial features that were overlapping, but was able to solve that by changing the values of the random integers near the end .

Leave a Reply