sketch
/* Cathy Dong
Section D
yinhuid
Project 2-Variable Face
*/
//Basics
var bodyG = 219;
var bodyB = 96;
var headW = 178;
var headH = 79;
var eyeW = 120;
var eyeH = 100;
var eyeR = 30;
var mX = 320;
var mY = 350;
var mW = 30;
var mH = 20;
var speedX = 1;
var startX = 0;
var speedY = 1;
var startY = 0;
var bananaX = 0;
var bananaY = 51;
function setup() {
createCanvas(640, 480);
}
function draw() {
background(233, 229, 228);
//hair variables
hairLx = width / 2 - headW / 2;
hairRx = width / 2 + headW / 2;
hairY = headH + 20;
//eye variables
ballLx = 315 - eyeW / 2;
ballRx = 325 + eyeW / 2;
ballY = 213;
//body shape
stroke(0);
strokeWeight(.5);
fill(251, bodyG, bodyB);
beginShape();
curveVertex(146, 480);
curveVertex(171, 349);
curveVertex(174, 200);
curveVertex(hairLx, hairY);
curveVertex(width / 2, headH);
curveVertex(hairRx, hairY);
curveVertex(466, 200);
curveVertex(469, 349);
curveVertex(494, 480);
curveVertex(494, 480);
endShape(CLOSE);
//cloth
stroke(8, 30, 56);
strokeWeight(1);
fill(94, 126, 163);
beginShape();
curveVertex(211, 480);
curveVertex(212, 448);
curveVertex(186, 423);
curveVertex(160, 385);
curveVertex(167, 358);
curveVertex(188, 394);
curveVertex(221, 418);
curveVertex(320, 429); //cloth mid point
curveVertex(419, 418);
curveVertex(452, 394);
curveVertex(473, 358);
curveVertex(480, 383);
curveVertex(454, 423);
curveVertex(441, 448);
curveVertex(443, 480);
curveVertex(443, 480);
endShape(CLOSE);
//pocket
stroke(48, 77, 112);
strokeWeight(2);
fill(68, 100, 143);
beginShape();
curveVertex(277, 480);
curveVertex(276, 460);
curveVertex(320, 468);
curveVertex(364, 460);
curveVertex(363, 480);
curveVertex(363, 480);
endShape(CLOSE);
//button
stroke(48, 77, 112);
strokeWeight(2);
fill(68, 100, 143);
circle(219, 435, 20);
circle(219, 435, 10);
circle(430, 435, 20);
circle(430, 435, 10);
//Left hair
stroke(0);
strokeWeight(5);
noFill();
line(width / 2, headH, hairLx, hairY);
line(width / 2, headH, hairLx - 30, hairY + 20);
line(width / 2, headH, hairLx + 50, hairY - 20);
//Right Hair
stroke(0);
strokeWeight(5);
noFill();
line(width / 2, headH, hairRx, hairY);
line(width / 2, headH, hairRx + 30, hairY + 20);
line(width / 2, headH, hairRx - 50, hairY - 20);
//Eye
stroke(0);
strokeWeight(.5);
fill(225);
ellipse(315 - eyeW / 2, 233, eyeW, eyeH);
ellipse(325 + eyeW / 2, 233, eyeW, eyeH);
//Eyeball
ballLx = mouseX;
ballLx = constrain(ballLx, 315 - eyeW + eyeR, 315 - eyeR);
ballRx = mouseX;
ballRx = constrain(ballRx, 325 + eyeR, 325 + eyeW - eyeR);
ballY = mouseY;
ballY = constrain(ballY, 233 - eyeH / 2 + eyeR, 233 + eyeH / 2 - eyeR);
//dark
noStroke();
fill(80, 67, 60);
circle(ballLx, ballY, eyeR);
circle(ballRx, ballY, eyeR);
//light
noStroke();
fill(53, 40, 33);
circle(ballLx, ballY, eyeR / 2);
circle(ballRx, ballY, eyeR / 2);
//glass
stroke(148, 148, 148);
strokeWeight(20);
noFill();
ellipse(255, 245, 125, 131);
ellipse(385, 245, 125, 131);
//glass shadow
stroke(175, 174, 175);
strokeWeight(10);
noFill();
ellipse(255, 245, 125, 131);
ellipse(385, 245, 125, 131);
//glass belt
stroke(96, 75, 58);
strokeWeight(2);
fill(62, 58, 54);
rect(165, 230, 23, 27);
rect(456, 230, 20, 27);
//Mouse
stroke(0);
strokeWeight(.5);
fill(225);
triangle(mX, mY, mX - mW / 2, mY - mH, mX + mW / 2, mY - mH);
//BANANA TEXT
stroke(198, 143, 79);
strokeWeight(3);
fill(225, 181, 143);
if (keyIsPressed) {
if ((key == 'a') || (key == 'A')) {
speedX = -1;
}
if ((key == 's') || (key == 'S')) {
speedX = 1;
}
if ((key == 'w') || (key == 'W')) {
speedY = -1;
}
if ((key == 'z') || (key == 'Z')) {
speedY = 1;
}
}
textSize(100);
text('BANANA', startX, startY);
startX += speedX;
startY += speedY;
startX = constrain(startX, 0, width - 450);
startY = constrain(startY, 80, height - 10);
//Banana fruit
bananaX = mouseX;
bananaX = constrain(bananaX, 0, width - 107);
bananaY = mouseY;
bananaY = constrain(bananaY, 52, height - 27);
stroke(206,154,8);
strokeWeight(1);
fill(255, 226, 0);
beginShape();
curveVertex(bananaX, bananaY);
curveVertex(bananaX + 54, bananaY - 3);
curveVertex(bananaX + 78, bananaY - 16);
curveVertex(bananaX + 90, bananaY - 31);
curveVertex(bananaX + 90, bananaY - 48);
curveVertex(bananaX + 98, bananaY - 50);
curveVertex(bananaX + 97, bananaY - 33);
curveVertex(bananaX + 103, bananaY - 31);
curveVertex(bananaX + 107, bananaY - 22);
curveVertex(bananaX + 90, bananaY + 11);
curveVertex(bananaX + 62, bananaY + 24);
curveVertex(bananaX + 47, bananaY + 27);
curveVertex(bananaX + 25, bananaY + 23);
curveVertex(bananaX + 13, bananaY + 20);
curveVertex(bananaX + 3, bananaY + 8);
endShape(CLOSE);
}
function mousePressed(){
bodyG = random(220, 95);
bodyB = random(95, 220);
headW = random(150, 200);
headH = random(75, 100);
eyeW = random(100, 130);
eyeH = random(100, 110);
eyeR = random(20, 40);
mX = random(315, 325);
mY = random(340, 380);
mW = random(25, 50);
mH = random(15, 45);
}
I had fun making minions. I sketched out the basic shapes based on a picture. The idea is to let his eye balls follow the banana, and make his face features and body color change with mouse click. The text “BANANA” move when pressing “w,” “a,” “z,” and “s,” capitalized or not.