//John Legelis
//Section D 3:00-4:30
//jlegelis@andrew.cmu.edu
//Project-02 Variable Faces; Face Variables
function setup() {
createCanvas(480, 640);
background(0);
}
var centerX
centerX = 480/2
var centerY
centerY = 640/2
function mousePressed() {
loop();
noLoop();
}
function draw() {
var BcolorR
BcolorR = random(126,240)
var BcolorG
BcolorG = random(126,240)
var BcolorB
BcolorB = random(126,240)
background(BcolorR,BcolorG,BcolorB);
// randomize face dimensions
var faceW;
faceW = random(0+100,480-100);
var faceH;
faceH = random(0+50,640-50);
var max_nose_gap
max_nose_gap = faceW/7
var max_eye_size
max_eye_size = faceW/2 - (max_nose_gap)
ellipseMode(CENTER);
var FcolorR
FcolorR = random(126,240)
var FcolorG
FcolorG = random(126,240)
var FcolorB
FcolorB = random(126,240)
fill(FcolorR,FcolorG,FcolorB);
//Draw Face
ellipse(centerX, centerY, faceW, faceH);
// randomize eye width in relation to face dimensions and not larger than largest possible
var eyeW;
eyeW = min((random(faceW / 6, faceW/2)),(max_eye_size));
// randomize eye height in relation to face dimensions
var eyeH;
eyeH = random(faceH/5, faceH/9);
// randomize eye placement within left side of place and not overlapping eye width with nose or edge of face
var pY;
pY = centerY;
//calculate leftmost left pupil X value
var lpXmin
lpXmin = centerX - faceW/2 + eyeW/2
//calulate rightmost left pupil X value
var lpXmax
lpXmax = centerX - eyeW/2 - (max_nose_gap/2)
var lpX;
lpX = random(lpXmin, lpXmax)
// draw left eye
fill(255)
ellipse(lpX, pY, eyeW, eyeH)
// draw left pupil
ellipseMode(CENTER);
fill(0);
ellipse(lpX, pY, eyeW/3, eyeH);
//figure out coordinate of right pupil
var centerX_to_lpX
centerX_to_lpX = centerX - lpX
var rpX
rpX = centerX + centerX_to_lpX
//draw right eye
fill(255)
ellipse(rpX, pY, eyeW, eyeH)
//draw right pupil
fill(0)
ellipse(rpX, pY, eyeW/3, eyeH)
//NOSE----------------------------------------------------------------------
//nose bridge -----------
// nose bridge top y
var nbtY
nbtY = centerY
// random nose bottom y
var nbY
nbY = random(centerY+faceH/6, centerY+faceH/3)
//random nose bridge width
var nbW
nbW = min(max_nose_gap, faceW/10)
print("noseWidth =" + nbW)
//nose bridge left x
var nblX
nblX = centerX - nbW/2
//nose bridge right x
var nbrX
nbrX = nblX + nbW
//draw nose bridge rectangle
fill(FcolorR,FcolorG,FcolorB)
rectMode(CORNERS)
rect(nblX,nbtY, nbrX,nbY)
//nose bulb------------
var bulbW
bulbW = random(faceW/6,faceW/8)
var bulbH
bulbH = random(faceH/10, faceH/15)
var bulbtX
bulbtX = centerX - bulbW/2
var bulbtY
bulbtY = nbY - bulbH
var bulbbX
bulbbX = centerX + bulbW/2
var bulbbY
bulbbY = nbY
rect(bulbtX, bulbtY, bulbbX, bulbbY)
//MOUTH------------------------------------------------------------------
var mW
mW = random(faceW/3, faceW/4)
var mH
mH = random(faceH/7, faceH/10)
var mcX
mcX = centerX
var mcY
mcY = ((nbY+ (centerY+faceH/2))/2)
rectMode(CENTER)
fill(FcolorR+40, FcolorG+40, FcolorB+40)
rect(mcX, mcY, mW, mH)
line(mcX-mW/2, mcY, mcX+mW/2, mcY)
noLoop();
}
This project demanded the use of variables because all of the facial variants were based on ratios involving the facial dimensions. These dimensions change with every click so the values for many dimensions of the face are derived from there.