Processing Face Animation

I made an animated face in Processing.

int numFrames = 14;
int frame = 0;
int bliFrames = 11;
int blink = 0;
int mouFrames = 8;
int mouth = 0;
long timer;
float framerate = 100;
int[] lookL = new int[numFrames];
int[] lookR = new int[numFrames];
int[] open = new int[numFrames];
int[] wide = new int[mouFrames];
int[] blinkEye = new int[bliFrames];
int[] blinkPup = new int[bliFrames];
void setup() {
size(300, 400);
background(0,130,0);
smooth();
lookL[0] = 100;
lookL[1] = 100;
lookL[2] = 110;
lookL[3] = 115;
lookL[4] = 115;
lookL[5] = 115;
lookL[6] = 110;
lookL[7] = 100;
lookL[8] = 90;
lookL[9] = 85;
lookL[10] = 85;
lookL[11] = 85;
lookL[12] = 90;
lookL[13] = 100;
lookR[0] = 186;
lookR[1] = 186;
lookR[2] = 196;
lookR[3] = 201;
lookR[4] = 201;
lookR[5] = 201;
lookR[6] = 196;
lookR[7] = 186;
lookR[8] = 176;
lookR[9] = 171;
lookR[10] = 171;
lookR[11] = 171;
lookR[12] = 176;
lookR[13] = 186;
open[0] = 1;
open[1] = 5;
open[2] = 10;
open[3] = 15;
open[4] = 20;
open[5] = 25;
open[6] = 20;
open[7] = 15;
open[8] = 10;
open[9] = 5;
blinkEye[0] = 40;
blinkEye[1] = 40;
blinkEye[2] = 30;
blinkEye[3] = 20;
blinkEye[4] = 10;
blinkEye[5] = 1;
blinkEye[6] = 10;
blinkEye[7] = 20;
blinkEye[8] = 30;
blinkEye[9] = 40;
blinkEye[10] = 40;
blinkPup[0] = 10;
blinkPup[1] = 10;
blinkPup[2] = 10;
blinkPup[3] = 10;
blinkPup[4] = 10;
blinkPup[5] = 1;
blinkPup[6] = 10;
blinkPup[7] = 10;
blinkPup[8] = 10;
blinkPup[9] = 10;
blinkPup[10] = 10;
wide[0] = 50;
wide[1] = 40;
wide[2] = 30;
wide[3] = 25;
wide[4] = 25;
wide[5] = 25;
wide[6] = 30;
wide[7] = 40;
timer = millis();
}

void draw() {
if (millis() – timer > framerate) {
timer = millis();
frame ++;
blink ++;
mouth ++;
}
if (frame == numFrames){
frame = 0;
}
if (blink == bliFrames){
blink = 0;
}
if (mouth == mouFrames){
mouth = 0;
}
fill(0,255,0);
ellipse(width/2, height/2, 200, 300); // head
fill(255);
ellipse(100, 180, 40, blinkEye[blink]); // left eye
ellipse(186, 180, 40, blinkEye[blink]); // right eye
fill(1);
ellipse(lookL[frame], 180, 10, blinkPup[blink]); // left pupil
ellipse(lookR[frame], 180, 10, blinkPup[blink]); // right pupil

fill(255,0,0);
ellipse(143, 280, wide[mouth], open[frame]); // mouth
}

Advertisements

About degrafgo

I am a fun, green loving guy who owns 3 YouTube channels under the name DeGraphics.
This entry was posted in Lectures & Workshops, Time Based and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s