In my first assignment I really wanted to incorporate some form of animation. I decided to focus on blinking eyes. I used arc() function to draw arcs and changed their start points as well as the endpoints with respect to other parts of the eye. I decided to split the animation into 3 parts: the eyelid, the iris and the pupil. The eyelid and the iris animate at the same intervals, but the iris needed a small adjustment, as the arc length of a circle did not correspond directly to that of an ellipse of the eyelid. The last part, the pupil, comes into play only when the eyelid is almost closed.
float eyelidPosition = 40; float irisPosition = 40; float pupilPosition = 5; float speed = 0.3; int skinColor = #FEB186; int mouthColor = #C18E74; void setup() { size(640, 360); background(255); } void draw() { background(255); drawFace(200, 200); } void drawEye(int x, int y) { //EyeShape ellipse(x, y, 60, 40); //Eyelid fill(skinColor); arc(x, y, 60, 40, PI, 2*PI); fill(255); //Eyelid animation arc(x, y, 60, eyelidPosition, PI, TWO_PI); arc(x, y, 40, 40, -irisPosition*PI/80, PI+irisPosition*PI/80); //Pupil fill(0); arc(x, y, 5, 5, -pupilPosition*PI/5, PI+pupilPosition*PI/5); fill(255); eyelidPosition = eyelidPosition+speed; irisPosition = eyelidPosition-3*PI; if (eyelidPosition < 5) { pupilPosition = pupilPosition+speed; } if (eyelidPosition < 0) { delay(int(random(7)*100)); eyelidPosition=0; speed=random(0.1,0.5); } else if (eyelidPosition > 40) { delay(int(random(5)*1000)); eyelidPosition=40; speed=-random(0.1,0.5); } if (irisPosition < 0) { irisPosition=0; } if (pupilPosition < 0) { pupilPosition=0; } } void drawSmile(int x, int y) { fill(mouthColor); arc(x, y, 150, 60, 0, PI); arc(x, y, 150, 20, 0, PI); fill(255); } void drawFace(int x, int y) { fill(skinColor); ellipse(x, y, 200, 250); fill(255); drawSmile(x, y+50); drawEye(x-50, y-30); drawEye(x+50, y-30); }
Mikolaj, please include a screen shot of your portrait, thanks!