Variable Faces

This project was extremely difficult for me because I kept making tiny mistakes which absolutely broke my code. This was definitely a learning experience, and towards the end I had more fun creating.

sketch
// Kathy Lee
//Section D

// Variable Setup
var faceHeight = 200;
var faceWidth = 200;
var shirt = 200;
var eye = 50;
var mouth = 50;

// Color Variables
var r = 50;
var g = 50;
var b = 50;

// mouthsize, hair length, eyesize

function setup() {
    createCanvas(640, 480);
    text("Smiling Alien", 10, 15);
}

function draw() {
    background (220);
    noStroke();

    // Shirt
    fill(200 - r, 200 - g, 200 - b);
    ellipse((width / 2), (height / 2) + 200, shirt + 100, shirt * 1.5);

    // Face
    fill(r + 50, g + 50, b + 50);
    ellipse(width / 2, (height / 2) + 50, faceWidth, faceHeight);

    // Eyes
    fill(r + 150, g + 150, b + 150);
    ellipse((width / 2.5) + 25, height / 2, faceWidth - 150, eye); // left eye
    fill(r + 150, g + 150, b + 150);
    ellipse((width / 2) + 40, height / 2, faceWidth - 150, eye); // right eye
    fill("black");
    ellipse((width / 2.5) + 20, height / 2, faceWidth - 200, eye - 30); // left pupil
    fill("black")
    ellipse((width / 2.5) + 110, height / 2, faceWidth - 200, eye - 30); // right pupil
    
    // Mouth
    fill(r + 175, g + 175, b + 175);
    ellipse(width / 2, (height / 2) + 75, mouth + 50, mouth / 2);
    fill(r + 50, g + 50, b + 50);
    ellipse(width / 2, (height / 2) + 70, mouth + 50, mouth / 2); // top ellipse to make smiling mouth

}

function mousePressed() {
    faceWidth = random(150, 300);
    faceHeight = random(150, 300);
    shirt = random(200, 300);
    eye = random(50, 60);
    mouth = random(50, 150);
    r = random(0, 255);
    g = random(0, 255);
    b = random(0, 255);
}

Leave a Reply