Project 2: Variable Face

sketch

//Name: Hari Vardhan Sampath
//Section: E

var x = 80;
var y = 160;
var eyeSize = 50;
var faceWidth = 200;
var faceHeight = 300;
var backgroundColor = 180
var chinWidth = 15
var mouthHeight1 = 20
var mouthHeight2 = 20 
var noseHeight = 100

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

function draw() {
    background(backgroundColor);

    // outline of face
    fill(210,180,140);
    beginShape();
    curveVertex(x*2, y);
    curveVertex(x*2, y);
    curveVertex(x, y*2);
    curveVertex(x*2 + chinWidth, y*3 + x/2);
    curveVertex(x*4 - chinWidth, y*3 + x/2);
    curveVertex(x*5, y*2);
    curveVertex(x*4, y);
    curveVertex(x*2, y);
    curveVertex(x*2, y);
    endShape();

    // mouth
    noFill();
    beginShape();
    vertex(x*2 + 30, y*3);
    bezierVertex(x*2 + 60, y*3 + mouthHeight1, 
        x*4 - 60, y*3 + mouthHeight2, x*4 - 30, y*3);
    endShape();

    // eyes
    fill(255,248,220);
    ellipse(x*2 + 10, y*2, eyeSize, eyeSize+5);
    ellipse(x*4 - 10, y*2, eyeSize, eyeSize+5);
    fill(0,0,0);
    ellipse(x*2 + 10, y*2, eyeSize/2, eyeSize/2);
    ellipse(x*4 - 10, y*2, eyeSize/2, eyeSize/2);

    // hair 
    fill(5,5,0);
    beginShape();
    curveVertex(x*2, y + x);
    curveVertex(x*2, y + x);
    curveVertex(x, y*2);
    curveVertex(x, y*2 - x);
    curveVertex(x*2, y - 15);
    curveVertex(x*4, y - 15);
    curveVertex(x*5, y*2 - 25);
    curveVertex(x*2, y + x);
    curveVertex(x*2, y + x)
    endShape();

    // nose
    fill(210,180,140);
    beginShape();
    curveVertex(x*3 - 30, y*2 + noseHeight - 20);
    curveVertex(x*3 - 30, y*2 + noseHeight - 20);
    curveVertex(x*3 - 30, y*2 + noseHeight - 10);
    curveVertex(x*3 - 15, y*2 + noseHeight - 15);
    curveVertex(x*3, y*2 + noseHeight);
    curveVertex(x*3 + 15, y*2 + noseHeight - 15);
    curveVertex(x*3 + 30, y*2 + noseHeight - 10);
    curveVertex(x*3 + 30, y*2 + noseHeight - 20);
    curveVertex(x*3 + 30, y*2 + noseHeight - 20);
    endShape();

}

function mousePressed() {
    // when the user clicks, these variables are reassigned
    // to random values within specified ranges. For example,
    // 'backgroundColor' gets a random value between 160 and 200.
    x = random(75, 95);
    y = random(150, 170);
    eyeSize = random(30, 70);
    backgroundColor = random(160, 200);
    chinWidth = random(0, 25);
    mouthHeight1 = random(-30, 40);
    noseHeight = randon(90, 110);
}

Leave a Reply