Project 2: Variable Face

sketch
// Ana Furtado 
// Section E

var noseSize = 20;
var r = 139;
var g = 69;
var b = 19;  // r g b is going to be randomlly 
            //generating blues for corneas when mouse is pressed
var a = 105; // y of more hair left strand 1
var b = 105; // y of more hair left strand 2
var x = 405; //y of more hair right strand 1
var y = 405; //y of more hair right strand 2
var eyeLeft = 190;
var eyeRight = 290;

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

function draw() {
    stroke(84, 18, 18);      // reddish brown
    strokeWeight(30);
    line(175, 160, 120, 620);      // back hair left
    line(175, 160, 155, 620);
    line(305, 160, 365, 620);     // back hair right
    line(305, 160, 315, 620);
    stroke(0, 0, 0);     // black
    strokeWeight(1);
    fill(0, 206, 209);     // light blue
    ellipse(140, 330, 30, 30);     // earrings
    ellipse(340, 330, 30, 30);
    fill(255, 228, 196);     // skin
    ellipse(240, 540, 75, 400);     // neck
    fill(255, 228, 196);     // skin
    ellipse(240, 320, 200, 400);     // face
    fill(255, 255, 255);     // white
    ellipse(190, 270, 50, 100);     // left eye
    ellipse(290, 270, 50, 100);     // right eye
    fill(r, g, b);    // brown
    ellipse(190, 270, 25, 50);     // left cornea
    ellipse(290, 270, 25, 50);     // right cornea
    fill(0);
    ellipse(eyeLeft, 270, 10, 20);     // left pupil 
    ellipse(eyeRight, 270, 10, 20);     // right pupil 
    fill(255, 228, 196);     // skin
    circle(240, 320, noseSize, noseSize);     // nose
    //line(190, 200, 190, 125);
    //line(210, 200, 210, 125);
    fill(220, 20, 60);     // red
    ellipse(240, 420, 110, 50)     // mouth
    line(185, 420, 295, 420);
    stroke(84, 18, 18);      // reddish brown
    strokeWeight(1);
    fill(84, 18, 18);     // reddish brown
    ellipse(240, 160, 150, 80);     // hair top
    strokeWeight(10);
    line(160, 160, 90, 620);      // hair left
    line(160, 160, 115, 620);
    line(160, 160, a, 620);
    line(160, 160, b, 620);
    line(310, 160, 415, 620);     // hair right
    line(310, 160, 390, 620);
    line(310, 160, x, 620);
    line(310, 160, y, 620);
    noStroke();
    fill(r, g, b);     // bow
    ellipse(305, 150, 20);
    ellipse(325, 150, 20);
}

function mousePressed() { 
    // when the user clicks, these variables are reassigned
    // to random values within specified ranges. For example,
    // 'noseSize' gets a random value between 10 and 30.
    // eye color changes as bow color changes to match
    // more left and right hair 
    // left and right pupils move
    noseSize = random(10, 30);
    r = random(0, 100);
    g = random(0, 250); 
    b = random(200, 250); 
    a = random(0, 175);
    b = random(0, 175);
    x = random(305,620);
    y = random(305,620);
    eyeLeft = random(177.5, 202.5);
    eyeRight = random(277.5, 302.5);
}

I started with the same proportions as the face for project 1. I modified it by changing the eye color, hair, and adding a bow. The pupils also move at the press of the mouse. The most challenging part was to get the pupils to move and understanding the difference between mouseIsPressed and mousePressed in practice.

Leave a Reply