the dude animation

For the second ICM project, i decided to animate my first project, the dude,…. so you can interact with the cartoon using the mouse (Y position, up and down).
Also while time pass there are stars appearing in the background.

heres the link to see the animation.

here’s the code:
float faceX=356;
float faceY=155;
float faceW=400;
float faceH=200;

float mouthX=faceX;
float mouthY=faceY+205;
float mouthW=faceW;
float mouthH=faceH-50;

float eyeX=290;
float eyeY=155;
float eyeW=70;
float eyeH=80;

//variables for the stars in background
float c;
float a;
float w;
float h;
float x;
float y;

//eyelids points
float eyeul=5*QUARTER_PI;
float eyeur=7*QUARTER_PI;
float eyedl=3*QUARTER_PI;
float eyedr=QUARTER_PI;
float addeye;

float aeyes=10;
void setup() {
size(720, 600);
smooth();
ellipseMode(RADIUS);
rectMode(CENTER);
fill(0);
rect(width/2, height/2, width, height);
}

void draw() {
// background(255);
// fill(137);
// ellipse(c,100,10,10);
// c++;

c=random(0, 2);
a = random(255);
w= random(1);
h= random(1);
x = random(width);
y = random(height*2/3);
// Use values to draw an ellipse
noStroke();
fill(255, a);
ellipse(x, y, w, h);
//background
fill(10, 200, 10);
rect(width/2, height*5/6, width, height/3);

//face and mouth rects
fill(255, 255, 90);
stroke(0);
strokeWeight(8);
strokeJoin(ROUND);
rect(faceX, faceY, faceW, faceH);
rect(mouthX, mouthY, mouthW, mouthH);
strokeWeight(6);
//triangles to draw a tongue and
fill(230, 100, 0);
triangle(mouthX-16, mouthY-75, mouthX+144, mouthY-75, mouthX+114, mouthY-35);
fill(0, 150);
triangle(mouthX+4, mouthY+50, mouthX-36, mouthY+10, mouthX+44, mouthY+10);
stroke(0, 150);

stroke(0);//line blck
strokeWeight(2);
fill(200, 100, 0);
ellipse(eyeX-14, eyeY, eyeW, eyeH);
ellipse(eyeX+146, eyeY, eyeW, eyeH);

fill(255);// INNER EYES
ellipse(eyeX, eyeY, eyeW, eyeH);
ellipse(eyeX+160, eyeY, eyeW, eyeH);
fill(255, 0, 0, aeyes);// INNER EYES
ellipse(eyeX, eyeY, eyeW, eyeH);
ellipse(eyeX+160, eyeY, eyeW, eyeH);

noStroke();//pupils
fill(10, 40, 200);
ellipse(eyeX+17+c, eyeY+3, eyeW-25, eyeH-30);
ellipse(eyeX+157+c, eyeY+3, eyeW-25, eyeH-30);

//eyelids
stroke(0);//line blck
fill(200, 100, 0);
arc(eyeX, eyeY, eyeW, eyeH, eyeul, eyeur,CHORD);
arc(eyeX, eyeY, eyeW, eyeH, eyedr, eyedl, CHORD);
arc(eyeX+160, eyeY, eyeW, eyeH, eyeul, eyeur, CHORD);
arc(eyeX+160, eyeY, eyeW, eyeH, eyedr, eyedl, CHORD);

addeye=map(1, 0, 40, 0, QUARTER_PI);//calculates the value to be added for the eyelids to close at same time as the mouth is moves.

//opening mouth, close lids, make eyes red when mouse goes down and stopping at a point even if mouse keeps going down.
if (mouthY>=399) {
mouthY=399;
eyeul=PI;
eyeur=2*PI;
eyedl=PI;
eyedr=0;
aeyes=120;
} else if (mouseY>pmouseY) {
mouthY=mouthY+1;
aeyes=aeyes+3;
eyeul=eyeul-addeye;
eyeur=eyeur+addeye;
eyedl=eyedl+addeye;
eyedr=eyedr-addeye;
}
//closing mouth, open lids, making eyes white when mouse goes up and stopping at a point even if mouse keeps going up.
if (mouthY<=360) { mouthY=360; eyeul=5*QUARTER_PI; eyeur=7*QUARTER_PI; eyedl=3*QUARTER_PI; eyedr=QUARTER_PI; aeyes=0; } else if (mouseY < pmouseY) { mouthY=mouthY-1; aeyes=aeyes-3; eyeul=eyeul+addeye; eyeur=eyeur-addeye; eyedl=eyedl-addeye; eyedr=eyedr+addeye; } }

Leave a Reply