Project 2: Generative Faces

Some faces, generated!

sketch

var eyeType = 3
var faceWidth = 200
var faceHeight = 275
var eyeSize = 60
var earSize = 60
var pupilSize = 40
var noseType = 1
var mouthType = 1
var blush = 1
var r = 89
var g = 74
var b = 58 //color 1, 2, & 3 used to be able to randomize the color of hair

function setup() {
    createCanvas(640, 480);
}
 
function draw() {
    background(252, 215, 91);
    strokeWeight(0);

    fill(r, g, b); //random hair color
    ellipse(width/2, (height/2)-((faceHeight-faceWidth)/2), faceWidth+20, faceWidth+20); //hair
    rect((width/2)-(faceWidth/2), height/2, faceWidth, faceHeight*(2/3)); //hair

    fill(194, 160, 97); //face/head
    ellipse(width/2, height/2, faceWidth, faceHeight); //chin
    ellipse(width/2, (height/2)-((faceHeight-faceWidth)/2), faceWidth, faceWidth); //to round out the top of the head better, less oval-y
    ellipse((width/2)-(faceWidth/2), height/2, earSize*(3/4), earSize); //left ear, size randomly generated
    ellipse((width/2)+(faceWidth/2), height/2, earSize*(3/4), earSize); //right ear, size ranomly generated

    fill(r, g, b); //random hair color for eyebrow
    ellipse((width/2)+(faceWidth/4), height/2-50, 40, 20);
    ellipse((width/2)-(faceWidth/4), height/2-50, 40, 20);

    if(blush <= 1) { //section to create blush possibility
    	fill(176, 121, 76, 255)
    } else {
    	fill(176, 121, 76, 0)
    }
    ellipse((width/2)-(faceWidth/4), (height/2)+40, 40, 20);
    ellipse((width/2)+(faceWidth/4), (height/2)+40, 40, 20);

    if(mouthType <= 1) { //section to create mouth type 1 (open)
        fill(77, 41, 34, 255)
    } else {
    	fill(77, 41, 34, 0)
    }
    ellipse(width/2, (height/2)+(faceHeight/3), 60, 30);
    if(mouthType <= 1) {
        fill(252, 251, 247, 255)
    } else {
    	fill(252, 251, 247, 0)
    }   
    ellipse(width/2, (height/2)+(faceHeight/3)-10, 40, 10);

    if(mouthType > 1 & mouthType < 2) { //section to create mouth type 2 (sad mouth)
    	fill(77, 41, 34, 255)
    } else {
    	fill(77, 41, 34, 0)
    }
    ellipse((width/2), (height/2)+(faceHeight/3)+7, 60, 40); //skin to carve out shape
     if(mouthType > 1 & mouthType < 2) { 
    	fill(194, 160, 97, 255)
    } else {
    	fill(194, 160, 97, 0)
    }
    ellipse(width/2, (height/2)+(faceHeight/3), 60, 40);

    if(mouthType >= 2) { //section to create mouth type 3 (happy mouth)
    	fill(77, 41, 34, 255)
    } else {
    	fill(77, 41, 34, 0)
    }
    ellipse((width/2), (height/2)+(faceHeight/3)-20, 60, 40); //skin to carve out shape
     if(mouthType >= 2) { 
    	fill(194, 160, 97, 255)
    } else {
    	fill(194, 160, 97, 0)
    }
    ellipse(width/2, (height/2)+(faceHeight/3)-27, 60, 40);

    if(eyeType <= 1) { //section to create eye type 1 (open regular)
        fill(242, 246, 247, 255)
    } else {
    	fill(242, 246, 247, 0)
    }
    ellipse((width/2)-(faceWidth/4), height/2, eyeSize, eyeSize);
    ellipse((width/2)+(faceWidth/4), height/2, eyeSize, eyeSize);
    if(eyeType <= 1) {
        fill(0, 0, 0, 255)
    } else {
    	fill(0, 0, 0, 0)
    }   
    ellipse((width/2)-(faceWidth/4)+1, height/2, pupilSize, pupilSize);
    ellipse((width/2)+(faceWidth/4)-1, height/2, pupilSize, pupilSize);

    if(eyeType > 1 & eyeType < 2) { //section to create eye type 2 (happy eye)
    	fill(77, 41, 34, 255)
    } else {
    	fill(252, 251, 247, 0)
    }
    ellipse((width/2)-(faceWidth/4), height/2, 60, 40);
    ellipse((width/2)+(faceWidth/4), height/2, 60, 40);
     if(eyeType > 1 & eyeType < 2) { 
    	fill(194, 160, 97, 255)
    } else {
    	fill(194, 160, 97, 0)
    }
    ellipse((width/2)-(faceWidth/4), (height/2)+7, 60, 40);
    ellipse((width/2)+(faceWidth/4), (height/2)+7, 60, 40);

    if(eyeType >= 2) { //section to create eye type 3 (sad eye)
    	fill(77, 41, 34, 255)
    } else {
    	fill(77, 41, 34, 0)
    }
    ellipse((width/2)-(faceWidth/4), height/2, 60, 40);
    ellipse((width/2)+(faceWidth/4), height/2, 60, 40);
    if(eyeType >= 2) { 
    	fill(194, 160, 97, 255)
    } else {
    	fill(194, 160, 97, 0)
    }
    ellipse((width/2)-(faceWidth/4), (height/2)-7, 60, 40);
    ellipse((width/2)+(faceWidth/4), (height/2)-7, 60, 40);

    if(noseType <= 1) { //section to create round nose type
    	fill(176, 121, 76, 255)
    } else {
    	fill(176, 121, 76, 0)
    }
    ellipse(width/2, (height/2)+20, 20, 60);

    if(noseType > 1) { //section to create triangle nose type
    	fill(176, 121, 76, 255)
    } else {
    	fill(176, 121, 76, 0)
    }
    triangle(width/2, (height/2), (width/2)-10, (height/2)+50, (width/2)+10, (height/2)+50);

}
 
function mousePressed() {
    r = random(0, 255);
    g = random(0, 255);
    b = random(0, 255);
    eyeType = random(0, 3); //eye type will be randomized, 1-3, and said # will correlate to an if else tree w eye options
    faceWidth = random(150, 225);
    faceHeight = random(226, 300);
    earSize = random(60, 80);
    pupilSize = random(30, 40);
    eyeSize = random(50, 70);
    noseType = random(0, 2); //nose type randomized based on two types
    mouthType = random(0,3);
    blush = random(0, 2); //whether or not blushing
}

Leave a Reply