Min Ji Kim Kim – Project 02 – Variable-Face

sketch

/*
Min Ji Kim Kim
Section-A
mkimkim@andrew.cmu.edu
Project-02
*/

//variables
var mouthHeight = 330;
var mouthWidth = 80;
var irisSize = 25;
var pupilSize = 12;
var headColor = 231;
var overallsColor = 130;
var eyeNumber = 2;


function setup() {
    createCanvas(640, 480);
    background(210, 210, 255);
}

function draw() {
    noStroke();
    //head
    fill(254, headColor, 81);
    rect(210, 150, 220, 300, 100, 100, 0, 0);

    //goggle band
    fill(47, 47, 41);
    rect(210, 235, 220, 20);

    //Number of eyes
    if (eyeNumber >= 2){
        //two eyes
        //goggles
        fill(201, 208, 202);
        circle(280, 245, 90);
        circle(360, 245, 90);
        //eyes
        fill(255);
        circle(280, 245, 70);
        circle(360, 245, 70);
        //iris
        fill(102, 45, 19);
        circle(280, 245, irisSize);
        circle(360, 245, irisSize);
        //pupils
        fill(0);
        circle(280, 245, pupilSize);
        circle(360, 245, pupilSize);

    } else {
        //one eye
        //goggle
        fill(201, 208, 202);
        circle(320, 245, 90);
        //eye
        fill(255);
        circle(320, 245, 70);
        //iris
        fill(102, 45, 19);
        circle(320, 245, irisSize);
        //pupil
        fill(0);
        circle(320, 245, pupilSize);

    }

    //overalls
    strokeWeight(1.5);
    stroke(172, 121, 77);
    fill(53, 96, overallsColor);
    rect(210, 400, 220, 50);

    //mouth
    fill(255);
    strokeWeight(3);
    stroke(200, 117, 0);
    arc(320, mouthHeight, mouthWidth, 80, 0, PI, CHORD);

}

function mousePressed(){
    // when the user clicks, these variables are reassigned
    // to random values within the specifed ranges.
    mouthHeight = random(300, 340);
    mouthWidth = random(30, 100);
    irisSize = random(20, 30);
    pupilSize = random(8, 16);
    headColor = random(180, 240);
    overallsColor = random(100, 250);
    eyeNumber = random(1,3);

}

I had so much fun doing the project this week. The hardest part was trying to figure out how to use the if statement to get the single or double eye as well as understanding how to manipulate variables for the mousePressed function.

Leave a Reply