Project 2: Variable Faces

generative faces

var faceWidth = 135;
var faceHeight = 150;
var eyeSize = 8;
var colG = 90
var colB = 40
var colR = 150
var earWidth = 19
var earHeight = 20
var hairColorR = 10
var hairColorG = 10
var hairColorB = 10
var hairHeight = 10
var hairCurve = 10
var hairWidth = 10
var noseWidth = 10
var noseHeight = 10
var noseColorR = 10
var noseColorG = 10
var noseColorB = 10
var mouthWidth = 10
var mouthHeight = 10
 
function setup() {
    createCanvas(480, 640);
}
 
function draw() {
    background(241,255,250);
    noStroke();

    fill(hairColorR, hairColorG, hairColorB) // hair
    ellipse(width / 2 , height / 2 - 40, hairWidth, hairHeight,)

    fill (colR, colG, colB)
    ellipse(width / 2 - 50, height / 2, earWidth, earHeight); // left ear

    fill (colR, colG, colB)
    ellipse(width / 2 + 50, height / 2, earWidth, earHeight); // left ear

    fill(colR, colG, colB)
    ellipse(width / 2, height / 2, faceWidth,  faceHeight); // face

    fill(hairColorR, hairColorG, hairColorB) // hair and face connector
    rect(200,255,75,25)

    fill(noseColorR, noseColorG, noseColorB) // nose
    ellipse(width / 2  , height / 2 + 10, noseWidth, noseHeight)

    fill (0) // eyes
    var eyeLeft = width / 2 - faceWidth * 0.25;
    var eyeRight = width / 2 + faceWidth * 0.25;
    ellipse(eyeLeft, height / 2, eyeSize, eyeSize);
    ellipse(eyeRight, height / 2, eyeSize, eyeSize);

    fill(0) //mouth
    ellipse(width / 2, height / 2 + 30, mouthWidth, mouthHeight)

    fill(colR, colG, colB) //mouth 2
    rect(210,335,60,15)

}

function mousePressed() {
    faceWidth = random(80,100);
    faceHeight = random(90,120);
    eyeSize = random(10, 20);
    colG = random(0,256);
    colR = random (0,256);
    colB = random(0,256);
    earWidth = random(28,30);
    earHeight = random(20,35);
    hairColorR = random(0,200);
    hairColorG = random(0,166);
    hairColorB = random(10,250);
    hairHeight = random(80,100);
    hairWidth = random(100,200);
    noseColorR = random(4,256);
    noseColorG = random(10,56);
    noseColorB = random(0,200);
    noseWidth = random(8,10);
    noseHeight = random(2,8);
    mouthWidth = random(20,30);
    mouthHeight = random(10,18);
}

It was quite a challenge trying to understand how to change certain features of the face while making everything connected at the same time and also thinking about how to randomize color was also challenging.

Leave a Reply