jjpeng assignment 2
var faceWidth = 120;
var faceHeight = 100;
var earRotation = 20;
var eyeSize = 10;
var cheekSize = 10;
var r = 244;
var g = 235;
var b = 130;
function setup() {
createCanvas(480, 640);
}
function draw() {
background (255, 255, 220);
// face
fill(r, g, b);
stroke(r, g, b);
ellipse(width / 2, height / 2, faceWidth, faceHeight);
// right ear
push();
translate(width / 2 + faceWidth / 3, height / 2 - faceHeight / 2);
rotate(radians(earRotation));
fill(r, g, b);
stroke(r, g, b);
ellipse(0, 0, 20, 70)
fill(60);
stroke(60);
arc(0, 0, 20, 70, PI + 1.2, 2 * PI - 1.2, OPEN)
pop();
// left ear
push();
translate(width / 2 - faceWidth / 3, height / 2 - faceHeight / 2);
rotate(radians(-earRotation));
fill(r, g, b);
stroke(r, g, b);
ellipse(0, 0, 20, 70)
fill(60);
stroke(60);
arc(0, 0, 20, 70, PI + 1.2, 2 * PI - 1.2, OPEN)
pop();
// eyes
fill(60);
stroke(60);
ellipse(width / 2 - faceWidth / 4, height / 2, eyeSize, eyeSize)
ellipse(width / 2 + faceWidth / 4, height / 2, eyeSize, eyeSize)
// nose
fill(60);
stroke(60);
triangle(width / 2 - faceWidth / 35, height / 2 + faceHeight / 20,
width / 2 + faceWidth / 35, height / 2 + faceHeight / 20,
width / 2, height / 2 + faceHeight / 12,);
// cheeks
fill(247, 98, 52);
stroke(247, 98, 52);
ellipse(width / 2 - faceWidth / 2.8, height / 2 + faceHeight / 6, cheekSize, cheekSize)
ellipse(width / 2 + faceWidth / 2.8, height / 2 + faceHeight / 6, cheekSize, cheekSize)
// hat
fill(58, 53, 50);
stroke(58, 53, 50);
arc(width / 2, height / 2 - faceHeight / 2.3, 45, 40, PI, 0);
ellipse(width / 2, height / 2 - faceHeight / 1.6, 6, 4);
fill(84, 79, 74);
stroke(84, 79, 74);
ellipse(width / 2, height / 2 - faceHeight / 2.3, 40, 10);
}
function mousePressed() {
// on click variables are randomly reassigned
faceWidth = random(100, 150);
faceHeight = random(100, 120);
earRotation = random (5, 60);
eyeSize = random(5, 20);
cheekSize = random(5, 20);
r = random (230, 255);
g = random (215, 235);
b = random (110, 130);
}