Animated Face using Code

Code:

int numFrames = 6;
int numOther = 2;
int frame = 0;
int other = 0;
int flash;
long timer;
color r;
color g;
color b;
float framespeed = 1000;
float otherspeed = 1000;
//(XY1=Bottomleft|XY2=Bottomright|XY3=Topright|XY=4Topleft)\\
void setup() {
size(300, 400);
smooth();
timer = millis();

}
void draw() {
r = color(255, 0, 0);
g = color(0, 255, 0);
b = color(0, 0, 255);
if (millis() – timer > framespeed) {
timer =millis();
frame ++;
}
if (frame == numFrames) {
frame = 0;
}
if (millis() – timer > otherspeed) {
timer =millis();
other ++;
}
if (other == numOther) {
other = 0;
}
fill(255);
ellipse(width/2, height/2, 200, 300); // head
ellipse(100, 180, 40, 40); // left eye
ellipse(186, 180, 40, 40); // right eye
fill(255);

if(other == 0){
fill(r);
}
if(other == 1){
fill(g);
}
if(other == 2);{
fill(b);
}
if(frame == 0){
ellipse(100, 180, 10, 10); // left pupil
ellipse(186, 180, 10, 10); // right pupil
fill(1);
quad(147, 272, 185, 270, 147, 272, 115, 270); // mouth
quad(172, 149, 210, 158, 211, 147, 171, 138);
quad(80, 158, 83, 147, 119, 138, 120, 147);
}
if(frame == 1){
ellipse(110, 180, 10, 10);
ellipse(196, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 159, 210, 168, 211, 157, 171, 148);
quad(80, 154, 83, 143, 119, 134, 120, 143);
}
if(frame == 2){
ellipse(90, 180, 10, 10);
ellipse(176, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 163, 210, 171, 211, 162, 171, 152);
quad(80, 150, 83, 139, 119, 130, 120, 139);
}
if(frame == 3){
ellipse(110, 180, 10, 10);
ellipse(196, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 163, 210, 171, 211, 162, 171, 152);
quad(80, 150, 83, 139, 119, 130, 120, 139);
framespeed = 100;
}
if(frame == 4){
fill(255, 0, 0);
ellipse(90, 180, 10, 10);
ellipse(176, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 163, 210, 171, 211, 162, 171, 152);
quad(80, 150, 83, 139, 119, 130, 120, 139);
}
if(frame == 5){
fill(0, 255, 0);
ellipse(110, 180, 10, 10);
ellipse(196, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 163, 210, 171, 211, 162, 171, 152);
quad(80, 150, 83, 139, 119, 130, 120, 139);
}
if(frame == 6){
fill(0, 0, 255);
ellipse(90, 180, 10, 10);
ellipse(176, 180, 10, 10);
fill(1);
quad(147, 256, 185, 270, 147, 256, 115, 270);
quad(172, 163, 210, 171, 211, 162, 171, 152);
quad(80, 150, 83, 139, 119, 130, 120, 139);
}
}

Advertisements
This entry was posted in Interactive Authoring 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