Catherine Coyle – Project 02 – Variable Faces

catherine faces

// Catherine Coyle
// Section C
// ccoyle@andrew.cmu.edu
// Project-02

var faceWidth = 300;
var faceHeight = 300;
var noseShape = 1;
var noseWidth = 50;
var noseHeight = 50;
var eyeSize = 50;
var eyeWidth = 100;
var eyeShape = 1;
// these are the coordinates of points on the mouth
var mouthY = 300;
var mouthMX = 320;
var mouthMY = 350;
var mouthLength=100
// skin color variables
var skinR = 250;
var skinG = 180;
var skinB = 140;
// pupils
var pupilSize = 30;
var pupilR = 0;
var pupilG = 0;
var pupilB = 0;
// other random features
var glasses = true;
var freckle = true;
var freckleX = 400;
var freckleY = 300;
var freckleSize = 5;
var blush = true;
var blushSize = 100;


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

function draw() {
	strokeWeight(0);
	background(239, 198, 198);
	// basic face
	fill(skinR,skinG,skinB);
	ellipse(width/2,height/2,faceWidth,faceHeight);
	// some random characteristics
	if (freckle == true) {
		fill(104, 54, 11);
		ellipse(freckleX, freckleY, freckleSize, freckleSize)
	}
	if (blush == true) {
		fill(skinR,skinG-50,skinB);
		ellipse((width/2)-(faceWidth/2)+blushSize/2,height/2,blushSize, blushSize);
		ellipse((width/2)+(faceWidth/2)-blushSize/2,height/2,blushSize, blushSize);
	}
	// eyes
	fill(255);
	if (eyeShape==1) {
		ellipse((width/2)-(eyeWidth/2),(height/2)-(faceHeight/4),eyeSize,eyeSize);
		ellipse((width/2)+(eyeWidth/2),(height/2)-(faceHeight/4),eyeSize,eyeSize);
	}
	else if (eyeShape==2) {
		rect((width/2)-(eyeWidth/2)-(eyeSize/2),(height/2)-(faceHeight/4)-(eyeSize/4),eyeSize,eyeSize/2);
		rect((width/2)+(eyeWidth/2)-(eyeSize/2),(height/2)-(faceHeight/4)-(eyeSize/4),eyeSize,eyeSize/2);
	}
	else if (eyeShape==3) {
		triangle((width/2)-(eyeWidth/2)-(eyeSize/2),(height/2)-(faceHeight/4)+(eyeSize/2),(width/2)-(eyeWidth/2)+(eyeSize/2),(height/2)-(faceHeight/4)+(eyeSize/2),(width/2)-(eyeWidth/2),(height/2)-(faceHeight/4)-(eyeSize*3/4));
		triangle((width/2)+(eyeWidth/2)-(eyeSize/2),(height/2)-(faceHeight/4)+(eyeSize/2),(width/2)+(eyeWidth/2)+(eyeSize/2),(height/2)-(faceHeight/4)+(eyeSize/2),(width/2)+(eyeWidth/2),(height/2)-(faceHeight/4)-(eyeSize*3/4));
	}
	// pupils
	fill(pupilR,pupilG,pupilB);
	ellipse((width/2)-(eyeWidth/2),(height/2)-(faceHeight/4),pupilSize,pupilSize);
	ellipse((width/2)+(eyeWidth/2),(height/2)-(faceHeight/4),pupilSize,pupilSize);
	// nose
	fill(skinR-50,skinG-20,skinB-20);
	if (noseShape == 1) {
		ellipse(width/2,height/2,noseWidth,noseHeight);
	}
	else if (noseShape == 2) {
		rect((width/2)-noseWidth/2,(height/2)-noseHeight/2,noseWidth,noseHeight);
	}
	else if (noseShape==3) {
		triangle((width/2)-noseWidth/2, (height/2)+(noseHeight/2),(width/2)+noseWidth/2, (height/2)+(noseHeight/2), width/2,(height/2)-(noseHeight/2));
	}
	// mouth
	strokeWeight(5);
	noFill();
	beginShape();
	curveVertex((width/2)-(mouthLength/2),mouthY);
	curveVertex((width/2)-(mouthLength/2),mouthY);
	curveVertex(mouthMX,mouthMY);
	curveVertex((width/2)+(mouthLength/2),mouthY);
	curveVertex((width/2)+(mouthLength/2),mouthY);
	endShape();
	// if they have glasses theyre added here
	if (glasses == true) {
		noFill();
		strokeWeight(5);
		stroke(0);
		ellipse((width/2)-(eyeWidth/2),(height/2)-(faceHeight/4),eyeWidth*3/4,eyeWidth*3/4);
		ellipse((width/2)+(eyeWidth/2),(height/2)-(faceHeight/4),eyeWidth*3/4,eyeWidth*3/4);
		line((width/2)-(eyeWidth/8),(height/2)-(faceHeight/4),(width/2)+(eyeWidth/8),(height/2)-(faceHeight/4))
	}
}

function mousePressed() {
	// randomizing all variables used for the face to make a new one!
	faceWidth=random(150,450);
	faceHeight=random(150,450);
	// randomizes the shape used for the nose
	// 1 means circle, 2 means rectangle, 3 means triangle
	noseShape = int(random(1,3.99));
	noseWidth = random(10,100);
	noseHeight = random(10,100);
	eyeWidth = random(20,faceWidth/2);
	eyeSize = random(20,eyeWidth/2);
	mouthLength = random(50,faceWidth*3/4);
	mouthY = (height/2)+faceHeight/4;
	mouthMY = random((height/2)+(noseHeight/2)+10, (height/2)+(faceHeight/2)-10);
	mouthMX = random((width/2)-(mouthLength/2)+10,(width/2)+(mouthLength/2)-10);
	skinR = random(183,255);
	skinG = random(120,skinR-60);
	skinB = skinG - random(30,60);
	pupilSize=random(5,eyeSize-10);
	pupilR = random(0,255);
	pupilG = random(0,255);
	pupilB = random(0,255);
	// eye shape works the same way as nose shape
	eyeShape = int(random(1,3.99));
	// randomizing extra features
	if (random(0,5) > 2) {
		glasses = false;
	}
	else {
		glasses = true;
	}
	if (random(0,10) > 6) {
		freckle = true;
		freckleX = (random(width/2, width/2 + faceWidth/2))*3/4;
		freckleY = (random(height/2, height/2 + faceHeight/2))*3/4;
		freckleSize = random(4,10);
	}
	else {
		freckle = false;
	}
	if (random(0,10) > 5) {
		blush = true;
		blushSize = random(50,faceWidth/2);
	}
	else {
		blush = false;
	}
}

 

I had a lot of fun with this project! I really wanted to emphasize the randomization so instead of creating a basic face set up and randomizing small parts, I decided to just create the face as if everything is randomly generated each time. Because of this, I didn’t make any sketches this time because it was impossible to predict anything about the faces. I wanted them all to be unrecognizable from one another. To help with this, I added variations to eye/nose shapes and also added additional features that aren’t on the face in every randomization. Initially I had wanted to add some kind of animation to this project but it ended up being to complicated with all the variability. Some of the faces end up being kind of funny/scary but I think it’s fun to click and see what the code can come up with!

Leave a Reply