var faceWidth = 50; //w,h variables for face
var faceHeight = 100;
var faceR = 172; //face color values
var faceG = 134;
var faceB = 94;
var eyes = 30; //variables for eyes
var eyesR = 102;
var eyesG = 178;
var eyesB = 102;
var earsWidth = 20; //variables for ears
var earsHeight = 40;
var earsR = 172;
var earsG = 134;
var earsB = 94;
var noseWidth = 15; //variables for nose
var noseHeight = 30;
var noseR = 188;
var noseG = 127;
var noseB = 126;
var pupil = 8; //variables for pupils
var pupilR = 66;
var pupilG = 16;
var pupilB = 16;
var mouthW = 60; //variables for mouth
var mouthH = 40;
var mouthR = 255;
var mouthG = 90;
var mouthB = 90;
var leftBrowX1 = 265; //variables for left eyebrow
var leftBrowY1 = 176;
var leftBrowX2 = 293;
var leftBrowY2 = 169;
var rightBrowX1 = 343; //variables for right eyebrow
var rightBrowY1 = 169;
var rightBrowX2 = 373;
var rightBrowY2 = 176;
function setup() {
createCanvas(640, 480);
}
function draw() {
if (mouseX < width * 0.33) { //background change colors depending on the mouse position
background(129, 129, 255);
}
else if (mouseX > width * 0.66) {
background(206, 206, 102);
} else {
background(193, 132, 193);
}
var earA = width / 2.35 - faceWidth * 1.3;//left ear
var earB = width / 1.75 + faceWidth * 1.3;//right ear
noStroke();
fill(earsR,earsG,earsB);
ellipse(earA, height / 2.1, earsWidth*2, earsHeight*2);
ellipse(earB, height / 2.1, earsWidth*2, earsHeight*2);
noStroke();
fill(faceR,faceG,faceB); //face
ellipse(width/2, height/2, faceWidth*4, faceHeight*3);
noStroke();
fill(noseR,noseG,noseB);//nose
ellipse(width/2, height/2.1, noseWidth, noseHeight*1.5);
noStroke();
var eyeA = width / 2 - faceWidth * 0.8;//left eye
var eyeB = width / 2 + faceWidth * 0.8;//right eye
fill(eyesR,eyesG,eyesB);
ellipse(eyeA, height / 2.3, eyes, eyes);
ellipse(eyeB, height / 2.3, eyes, eyes);
var pupilA = width / 2 - faceWidth * 0.8;//left pupil
var pupilB = width / 2 + faceWidth * 0.8;//right pupil
fill(pupilR,pupilG,pupilB);
ellipse(pupilA, height / 2.3, pupil, pupil);
ellipse(pupilB, height / 2.3, pupil, pupil);
fill(mouthR,mouthG,mouthB); //mouth
arc(width/2, height/1.7, mouthW, mouthH, 0, PI);
strokeWeight(8);
stroke(255,69,0);
line(leftBrowX1,leftBrowY1,leftBrowX2,leftBrowY2);//left eyebrow
line(rightBrowX1,rightBrowY1,rightBrowX2,rightBrowY2);//right eyebrow
}
function mousePressed() {
faceWidth = random(40,95);
faceHeight = random(50,150);
faceR = random(190,165);
faceG = random(150,127);
faceB = random(110,87);
eyes = random(15,48);
eyesR = random(120,90);
eyesG = random(198,158);
eyesB = random(100,80);
noseWidth = random(10,25);
noseHeight = random(20,45);
noseR = random(250,178);
noseG = random(160,117);
noseB = random(140,116);
earsWidth = random(18,35);
earsHeight = random(35,60);
earsR = random(180,165);
earsG = random(140,87);
earsB = random(100,87);
pupil = random(7,20);
pupilR = random(170,80);
pupilG = random(8,70);
pupilB = random(7,100);
mouthW = random(40,110);
mouthH = random(25,83);
mouthR = random(350,230);
mouthG = random(50,130);
mouthB = random(75,115);
}
During this project, I realized the importance of organizing and commenting on my codes so it will not only be easier on others to see but for myself as well. Also, although it took awhile, I got familiar with the use of variables and random functions.