Jamie Dorst Project 02 Variable Faces

sketch

/*
Jamie Dorst
Section A
jdorst@andrew.cmu.edu
project-02
*/

// variables
var eyeSize = 20;
var faceWidth = 150;
var faceHeight = 180;
var r, g, b
var faceCorners = 120
var irisSize = 15;
var eyeR, eyeG, eyeB
var pupilSize = 12
var mouthWidth = 50
var mouthHeight = 25
var noseWidth = 15
var noseHeight = 10
var mouthR, mouthG, mouthB
 
function setup() {
    createCanvas(640, 480);

    // choose random canvas starting color
    r = random(255);
    g = random(255);
    b = random(255);

    // choose random eye starting color
    eyeR = random(255);
    eyeG = random(255);
    eyeB = random(255);

    // choose random mouth starting color
    //reddish hue
    mouthR = random(51, 255);
    mouthG = random(204);
    mouthB = random(204);
}
 
function draw() {
    noStroke();
    background(r, g, b);

    // face
    fill('#EAC086');
    rectMode(CENTER);
    rect(width / 2, height / 2, faceWidth, faceHeight, faceCorners, faceCorners, faceCorners, faceCorners);

    // eyes
    // whites
    fill('white');
    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);
    // iris
    fill(eyeR, eyeG, eyeB);
    ellipse(eyeLX, height / 2, irisSize, irisSize);
    ellipse(eyeRX, height / 2, irisSize, irisSize);
    // pupil
    fill('black');
    ellipse(eyeLX, height / 2, pupilSize, pupilSize);
    ellipse(eyeRX, height / 2, pupilSize, pupilSize);

    // mouth
    noFill();
    strokeWeight(4);
    strokeCap(ROUND);
    stroke(mouthR, mouthG, mouthB);
    arc(width / 2, height / 2 + .25 * faceHeight, mouthWidth, mouthHeight, 0, PI);

    // nose
    stroke(51);
    strokeWeight(2);
    arc(width / 2, height / 2 + .1 * faceHeight, noseWidth, noseHeight, 0, PI);
}
 
function mousePressed() {
    // randomize sizes, colors upon click
    faceHeight = random(120, 220);
    faceWidth = random(100, faceHeight);
    eyeSize = random(10, 30);
    r = random(255);
    g = random(255);
    b = random(255);
    faceCorners = random (80, 140);
    irisSize = random(5, eyeSize - 1);
    eyeR = random(255);
    eyeG = random(255);
    eyeB = random(255);
    pupilSize = random(1, irisSize - 1);
    mouthWidth = random(5, 90);
    mouthHeight = random(2, 40);
    noseWidth, noseHeight = random(5, 25);
    mouthR = random(51, 255);
    mouthG = random(0, mouthR - 50);
    mouthB = random(0, mouthR - 50);

}

For this project, I started with the template that was given and added some of my code from last week’s face project to create a base face. Then I added in some variables, thought about what to change, and ended up finding a way to have sizes change but keep them relatively proportional (ie. have the size of the pupil change but not have it be bigger than the iris). I also found it fun to change colors and learn how to randomize something like that where it’s not as simple as a range of two numbers.

Leave a Reply