/*Kevin Riordan
Section C
kzr@andrew.cmu.edu
project_02*/
//variables for background color, random stuff
var backColorR = 0;
var backColorG = 0;
var backColorB = 0;
var strokeR = 0;
//variable for eyes (position, color, and size)
var eyeWidth = 0;
var eyeHeight = 0;
var eyeColorR = 0;
var eyeColorG = 0;
var eyeColorB = 0;
var eyePosX = 0;
var eyePosY = 0;
var eyeballWidth = 0;
var eyeballHeight = 0;
//variable for eyebrows
var browColor = 0;
var browL = 0;
var browR = 0;
//variable for face size
var faceWidth = 0;
var faceHeight = 0;
//variable for neck size
var neckW = 0;
//variable for hat color and coordinates
var hatColorR = 0;
var hatColorB = 0;
var hatColorG = 0;
var hat1 = 0;
var hat2 = 0;
var hat3 = 0;
var hat4 = 0;
var hat5 = 0;
var hat6 = 0;
//variable for nose width and height
var noseW = 0;
var noseH = 0;
//variable for mouth color and curve
var mouthR = 0;
var mouthB = 0;
var mouthG = 0;
var mouthCurveI = 0;
var mouthCurveF = 0;
var mouthStart = 0;
var mouthWeight = 0;
var mouthInside1 = 0;
var mouthInside2 = 0;
var mouthInside3 = 0;
function setup() {
createCanvas(480, 640);
}
function draw() {
background(backColorR,backColorG,backColorB);
//neck
stroke(0);
strokeWeight(2);
fill(250,220,200);
rect(240-(neckW/2),320,neckW,320);
//face
ellipse(240,320,faceWidth,faceHeight);
//eyes
strokeWeight(strokeR);
fill(255);
ellipse(eyePosX, eyePosY, eyeWidth, eyeHeight);
ellipse(480-eyePosX, eyePosY, eyeWidth, eyeHeight);
strokeWeight(strokeR+2);
fill(eyeColorR,eyeColorB,eyeColorG);
ellipse(eyePosX, eyePosY, eyeballWidth, eyeballHeight);
ellipse(480-eyePosX, eyePosY, eyeballWidth, eyeballHeight);
//eyebrows
strokeWeight(strokeR+3);
stroke(strokeR);
noFill();
beginShape();
curveVertex(eyePosX-(eyeWidth/2)-(browL*2),eyePosY-(eyeHeight/2)+browL);
curveVertex(eyePosX-(eyeWidth/2)-(browL*2),eyePosY-(eyeHeight/2)+browL);
curveVertex(eyePosX, eyePosY-(eyeHeight/2)-(browL*2));
curveVertex(eyePosX+(eyeWidth/2)+(browL*2),eyePosY-(eyeHeight/2)+(browL));
curveVertex(eyePosX+(eyeWidth/2)+(browL*2),eyePosY-(eyeHeight/2)+(browL));
endShape();
beginShape();
curveVertex(480-eyePosX-(eyeWidth/2)-(browR*2),eyePosY-(eyeHeight/2)+browR);
curveVertex(480-eyePosX-(eyeWidth/2)-(browR*2),eyePosY-(eyeHeight/2)+browR);
curveVertex(480-eyePosX, eyePosY-(eyeHeight/2)-(browR*2));
curveVertex(480-eyePosX+(eyeWidth/2)+(browR*2), eyePosY-(eyeHeight/2)+browR);
curveVertex(480-eyePosX+(eyeWidth/2)+(browR*2), eyePosY-(eyeHeight/2)+browR);
endShape();
//mouth
stroke(mouthR,mouthB,mouthG);
strokeWeight(mouthWeight);
fill(mouthInside1,mouthInside2,mouthInside3);
beginShape();
curveVertex(eyePosX,eyePosY+mouthStart);
curveVertex(eyePosX,eyePosY+mouthStart);
curveVertex(240,eyePosY+mouthStart+mouthCurveF);
curveVertex(480-eyePosX,eyePosY+mouthStart);
curveVertex(480-eyePosX,eyePosY+mouthStart);
endShape();
fill(250,220,200);
beginShape();
curveVertex(eyePosX,eyePosY+mouthStart);
curveVertex(eyePosX,eyePosY+mouthStart);
curveVertex(240,eyePosY+mouthStart+mouthCurveI);
curveVertex(480-eyePosX,eyePosY+mouthStart);
curveVertex(480-eyePosX,eyePosY+mouthStart);
endShape();
//nose
stroke(0);
strokeWeight(2);
fill(250,220,200);
beginShape();
curveVertex(240-(noseW/2),320+(faceHeight/8));
curveVertex(240-(noseW/2),320+(faceHeight/8));
curveVertex(240,320-noseH);
curveVertex(240+(noseW/2),320+(faceHeight/8));
curveVertex(240+(noseW/2),320+(faceHeight/8));
endShape();
strokeWeight(strokeR-1);
line(240-(noseW/2),320+(faceHeight/8),240+(noseW/2),320+(faceHeight/8));
//hat
strokeWeight(4);
fill(hatColorR,hatColorB,hatColorG);
triangle(hat1,hat2,hat3,hat4,hat5,hat6);
}
function mousePressed() {
backColorR = random(0,255);
backColorG = random(0,255);
backColorB = random(0,255);
hatColorR = random(0,255);
hatColorB = random(0,255);
hatColorG = random(0,255);
mouthR = random(0,255);
mouthB = random(0,255);
mouthG = random(0,255);
mouthCurveI = random(0,25);
mouthCurveF = random(eyeWidth,eyeWidth*1.3);
mouthStart = random(60,90);
mouthWeight = random(2,5);
mouthInside1 = random(100,200);
mouthInside2 = random(100,200);
mouthInside3 = random(100,200);
strokeR = random(1,5);
eyeWidth = random(30,80);
eyeHeight = random(30,80);
eyeballWidth = random(10,80);
eyeballHeight = random(10,80);
eyeballHeight = constrain(eyeballHeight,10,eyeHeight-10);
eyeballWidth = constrain(eyeballWidth,10,eyeWidth-10);
faceWidth = random(350,450);
faceHeight = random(400,550);
noseW = random(40,140);
noseH = random(40,60);
neckW = random(160,450);
neckW = constrain(neckW,160,faceWidth-180);
eyeColorR = random(100,200);
eyeColorB = random(50,150);
eyeColorG = random(75,175);
eyePosX = random(130,150);
eyePosY = random(280,350);
browColor = random(0,255);
browL = random(5,15);
browR = random(5,15);
hat1= 240-(faceWidth/1.5);
hat1= constrain(hat1,0,480);
hat2= 320-(faceHeight/1.8)+150;
hat2= constrain(hat2,0,640);
hat3= 240;
hat4= 320-(faceHeight/2)-80;
hat4= constrain(hat4,0,640);
hat5= 240+(faceWidth/1.5);
hat5= constrain(hat5,0,480);
hat6= 320-(faceHeight/1.8)+150;
hat6= constrain(hat6,0,640);
}
I changed a lot of variables for the face, so every time the mouse is clicked a lot of colors and shapes and positions change. Sometimes the face looks pretty weird, but I used constrain for a lot of the variables so the face should still look like a face no matter what. I also think I layered the mouth behind the nose well, so even when the mouth overlaps the nose, it just looks like the nose is hanging over the mouth.