Project-02-Face-Variables

sketch
//Nami Numoto
//15104 1A
// Simple beginning template for variable face.
var eyeSize = 20;
var faceWidth = 100;
var faceHeight = 150;
var noseWidth = 20;
var noseDirection = 0;
var noseHeight = 30;
var mouthPosition = 200;
var mouthHeight = 20;

function setup() {
    createCanvas(300, 300);
}

function draw() {
    strokeWeight(2);
    background(180);
    fill(156, 132, 104);
    ellipse(width / 2, height / 2, faceWidth,  faceHeight);
    var eyeLX = width / 2 - faceWidth * 0.25;
    var eyeRX = width / 2 + faceWidth * 0.25;
    fill(255)
    ellipse(eyeLX, height / 2, eyeSize, eyeSize); // eye 1
    ellipse(eyeRX, height / 2, eyeSize, eyeSize); // eye 2
    fill(0)
    ellipse(eyeLX, height / 2, eyeSize / 2, eyeSize / 2); // iris 1
    ellipse(eyeRX, height / 2, eyeSize / 2, eyeSize / 2); // iris 2
    line(width / 2, height / 2, noseWidth + width / 2, noseHeight + height / 2); // directional nose line
    line(width / 2, height / 2 + noseHeight, noseWidth + width / 2, height / 2 + noseHeight); // bottom nose line
    noFill();
    beginShape(); //creative rendition of a mouth, testing out curveVertex()  :)
    curveVertex(width / 2 - faceWidth / 3, mouthPosition + mouthHeight);
    curveVertex(width / 2 - faceWidth / 3, mouthPosition + mouthHeight);
    curveVertex(width / 2, mouthPosition);
    curveVertex(width / 2 + faceWidth / 3, mouthPosition + mouthHeight);
    curveVertex(width / 2 + faceWidth / 3, mouthPosition + mouthHeight);
    endShape(); //sometimes the mouth goes off the face. call it art
}

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(75, 150);
    faceHeight = random(100, 200);
    eyeSize = random(10, 30);
    noseWidth = random(10, 30);
    noseDirection = random(0, 2);
    if (noseDirection > 1) {
        noseWidth = -1 * noseWidth;
    }
    mouthHeight = random(-10, 10);
}

Leave a Reply