/** * A smiley face * *

Elie Zananiri
* ACAD Processing workshop
* April 2008

*/ void setup() { size(400, 400); smooth(); } void draw() { background(255); int smileySize = width-abs(width/2-mouseX)*2; drawSmiley(mouseX, mouseY, smileySize); } /* draws a smiley face with eyes, a nose, and a mouth */ void drawSmiley(int x, int y, int s) { stroke(0); // black outlines // draw the features drawHead(x, y, s); drawTwoEyes(x, y-s/5, s/5); drawNose(x, y+s/8, s/5); drawMouth(x, y+s/5, s/2, s/5); } /* draws the head shape */ void drawHead(int headX, int headY, int headSize) { // draw the head fill(255, 226, 3); // yellow ellipse(headX, headY, headSize, headSize); } /* draws two eyes */ void drawTwoEyes(int eyesX, int eyesY, int eyeSize) { drawEye(eyesX-eyeSize, eyesY, eyeSize); // draw the left eye drawEye(eyesX+eyeSize, eyesY, eyeSize*3/2); // draw the right eye } /* draws an eye */ void drawEye(int eyeX, int eyeY, int eyeSize) { stroke(0); // draw the white of the eye fill(255); ellipse(eyeX, eyeY, eyeSize, eyeSize); // draw the black pupil fill(0); ellipse(eyeX, eyeY+eyeSize/4, eyeSize/2, eyeSize/2); } /* draws the nose */ void drawNose(int noseX, int noseY, int noseSize) { noStroke(); fill(100, 100); // grey triangle(noseX-noseSize/4, noseY+noseSize/4, noseX-noseSize/2, noseY, noseX+noseSize/2, noseY); } /* draws the mouth */ void drawMouth(int mouthX, int mouthY, int mouthWidth, int mouthHeight) { stroke(0); // black noFill(); arc(mouthX, mouthY, mouthWidth, mouthHeight, 0, PI); }