//initialize variables to be randomized
var faceWidth = 480;
var eyeSize = 240;
var eyeColorR = 19;
var eyeColorG = 175;
var eyeColorB = 26;
var noseSize = 350;
var stacheWidth = 3;
function setup() {
createCanvas(480,640);
}
function draw() {
background(255);
//head
fill(242,208,239);
noStroke();
ellipse(240,240,faceWidth,640);
//eyes
stroke (0);
strokeWeight (1);
fill(255);
ellipse(144,240,eyeSize,eyeSize);
ellipse(336,240,eyeSize,eyeSize);
//iris
fill(eyeColorR, eyeColorG, eyeColorB);
noStroke();
ellipse(144, 240, eyeSize / 2, eyeSize /2);
ellipse(336, 240, eyeSize / 2, eyeSize /2);
//pupils
fill(0)
noStroke();
ellipse(144,240,eyeSize/5,eyeSize/5);
ellipse(336,240,eyeSize/5,eyeSize/5);
//nose
fill(218,0,165);
triangle (240,noseSize,216,425,264,425);
//mustache
stroke(40,17,0);
strokeWeight(stacheWidth);
line(80,441,80,466);
line(90,444,90,469);
line(100,447,100,472);
line(110,450,110,475);
line(120,453,120,478);
line(130,454,130,480);
line(140,456,140,482);
line(150,458,150,484);
line(160,459,160,485);
line(170,460,170,486);
line(180,461,180,487);
line(190,462,190,488);
line(200,463,200,489);
line(210,463,210,489);
line(220,463,220,489);
line(230,463,230,489);
line(240,463,240,489);
line(250,463,250,489);
line(260,463,260,489);
line(270,463,270,489);
line(280,463,280,489);
line(290,462,290,488);
line(300,461,300,487);
line(310,460,310,486);
line(320,459,320,485);
line(330,458,330,484);
line(340,456,340,482);
line(350,454,350,480);
line(360,453,360,478);
line(370,450,370,475);
line(380,447,380,472);
line(390,444,390,469);
line(400,441,400,466);
//mouth
noFill();
stroke(218,0,165);
strokeWeight(5);
arc(240,345,576,310,0,PI);
//hat
fill(0);
noStroke();
arc(240,0,350,200,0,PI);
}
//change face dimensions when mouse is clicked
function mousePressed() {
faceWidth = random(200,480);
eyeSize = random(50, 288);
eyeColorR = random(0,255);
eyeColorG = random(0,255);
eyeColorB = random(0,255);
noseSize = random(300,450);
stacheWidth = random(0,15);
}
I chose to continue working with my face project from last week. In doing so, I learned why hard-coding numbers can make things difficult down the line: when I changed the canvas size my face didn’t fit in the frame, and after changing that I needed to adjust quite a few numbers to make the proportions match on the facial features. In future I will plan to create more variables and do much less hard-coding of numbers.