// Variables Needed for Face
// Variable to create ellipse (circle) for eyes
var eyeSize = 25;
// Variables regarding width and height of ellipse for face
var fW = 400;
var fH = 540;
// Variable to create ellipse (circle) for nose
var noseSize = 6;
// Variables regarding width and height of rectangle for mouth
var mW = 80;
var mH = 50;
// Variables needed to change color of face features
// Left eye color
var RleftEyeColor = 120;
var GleftEyeColor = 100;
var BleftEyeColor = 75;
// Right eye color
var RrightEyeColor = 50;
var GrightEyeColor = 75;
var BrightEyeColor = 125;
// Nose color
var RnoseColor = 75;
var GnoseColor = 75;
var BnoseColor = 75;
// Mouth color
var RmouthColor = 50;
var GmouthColor = 75;
var BmouthColor = 125;
// Face color
var RfaceColor = 50;
var GfaceColor = 75;
var BfaceColor = 125;
function setup() {
createCanvas(480, 640);
}
function draw() {
background(0,0,0);
// Drawing face outline
fill(RfaceColor,GfaceColor,BfaceColor);
ellipse(width/2, height/2, fW, fH);
// Drawing left eye (pupil)
fill(RleftEyeColor,GleftEyeColor,BleftEyeColor);
stroke(10);
ellipse(width/2-fW*0.25, height/2, eyeSize, eyeSize);
// Drawing right eye (pupil)
fill(RrightEyeColor,GrightEyeColor,BrightEyeColor);
stroke(10);
ellipse(width/2+fW*0.25, height/2, eyeSize, eyeSize);
// Drawing nose
fill(RnoseColor,GnoseColor,BnoseColor);
stroke(5);
rect(width/2, height/2, noseSize, noseSize);
// Drawing mouth
fill(255,255,255);
rect(width/2, height/2+fH*0.25, mW, mH);
}
function mousePressed() {
// Face changes
eyeSize = random(15, 30);
fW = random(325, 400);
fH = random(525, 600);
noseSize = random(5, 30);
mW = random(50, 75);
mH = random(50, 75);
// Left eye color
RleftEyeColor = random(25,150);
GleftEyeColor = random(25,150);
BleftEyeColor = random(25,150);
// Right eye color
RrightEyeColor = random(25,150);
GrightEyeColor = random(25,150);
BrightEyeColor = random(25,150);
// Nose color
RnoseColor = random(25,150);
GnoseColor = random(25,150);
BnoseColor = random(25,150);
// Mouth color
var RmouthColor = 50;
var GmouthColor = 75;
var BmouthColor = 125;
// Face color
var RfaceColor = 50;
var GfaceColor = 75;
var BfaceColor = 125;
}
Using variables in this project turned out to be much more challenging than I expected. Many of the variables I tried to use did not initially work as I intended, and I felt like I was doing a lot more guessing and checking (similar to figuring out the coordinates in last week’s project). I had originally made a sketch of some of the kind of faces I wanted to make, but because I struggled so much with the variables, I ended up making a very basic face.