variablefaces
/*
*Sadie Johnson
*15-104 Section C
*sajohnso@andrew.cmu.edu
*Project-02
*This program draws random faces
*/
var eyeWidth = 20;
var eyeHeight = 20;
var faceWidth = 100;
var faceHeight = 150;
var earSize = 30;
var x = 10;
var lensSize = 40;
var hairWidth = 100;
var hairHeight = 100;
var mouthSize = 30;
function setup() {
createCanvas(640, 480);
g = color(120);
b = color(120);
//rgb colors for the hair
//i wanted to put them in certain range
h = color(10);
i = color(15);
j = color(20);
}
function draw() {
//fill();
background(234,237,216);
//draw background triange
fill(140, g, b, 127); //color
triangle(0, 0, 0, 480, 640, 480);
//draw hair
fill (h,i,j); //random hair color
ellipse(width / 2, height / 2 - 30, hairWidth, hairHeight);
//draw ears
fill (168, 133, 73);
var earLX = width / 2 - faceWidth / 2
var earRX = width / 2 + faceWidth / 2
ellipse(earLX, height / 2 + x, earSize, earSize);
ellipse(earRX, height / 2 + x, earSize, earSize);
//draw face
ellipse(width / 2, height / 2, faceWidth, faceHeight);
//draw eyes
fill(225);
var eyeLX = width / 2 - faceWidth * 0.25;
var eyeRX = width / 2 + faceWidth * 0.25;
ellipse(eyeLX, (height/2) -5, eyeWidth, eyeHeight);
ellipse(eyeRX, (height/2) -5, eyeWidth, eyeHeight);
//draw glasses
fill(140, g, b, 127); //color glasses
ellipse(eyeLX, height/2 + x, lensSize, lensSize);
ellipse(eyeRX, height/2 + x, lensSize, lensSize);
//noFill();
//draw bridge of glasses
var arcStart = (width/2) - (eyeWidth*.25)
var arcFin = (width/2) + (eyeWidth*.25)
line(arcStart, height/2, arcFin, height/2);
//draw mouth
fill(89,23,23);
arc(width/2, height/2 + 40, mouthSize, mouthSize, 0, PI+QUARTER_PI, PIE);
}
function mousePressed() {
// when the user clicks, these variables are reassigned
// to random values within specified ranges. For example,
// 'faceWidth' gets a random value between 75 and 150.
faceWidth = random(100, 175);
faceHeight = random(100, 200);
eyeWidth = random(10, 30);
eyeHeight = random(10, 30);
earSize = random(15,40);
x = random(0,20);
g = random(0,225);
b = random(0,225);
hairWidth = random(100,175);
hairHeight = random(100,200);
h = random(0,225);
i = random(0,225);
j = random(1,20);
mouthSize = random(5,35);
}
The hardest part of this assignment by far was making sure that all of the features remained on the face- that is, that everything was controlled by interlocking variables and not “magic numbers”.