//state variables
int ball1x = 100;
int ball1y = 150;
int ball2x= 150;
int ball2y= 80;
int ball3x = 300;
int ball3y = 70;
int ball4x = 270;
int ball4y = 120;
boolean isFoodFilled;
boolean ball1= false;
boolean ball2= false;
boolean ball3= false;
boolean ball4= false;
int milliseconds = (int) millis();
int milliseconds2 = (int) millis();
int randomTime = (int)random(1, 5);
int reset = 0; //resets milliseconds
int reset2 = 0;
//setup method
void setup(){size(400, 400);}
//draw method
void draw (){
//draw the bg
drawBG();
//draw the back objects
bodyDraw();
//draw the head depending on if the food is filled or the balls are played with
if (isFoodFilled){drawEatHead();}
else if (ball1 || ball2 ||ball3 ||ball4){drawMotionHead();}
else{drawNeutralHead();}
//draw the balls
drawBalls();
//run the foreground method
cageDraw();
}
//method to draw the eating head
//as well as using the timer to have the head stay in place
void drawEatHead(){
//if the timer is still true, or the animation is supposed to be shown, show the eating bird
if (timer (90) == true){
fill(100, 100, 255);
quad(211, 158, 185, 163, 181, 177, 173, 148);
ellipse(195 -25, 130 + 36, 40, 40);
triangle (178 -25, 119 + 36, 220 -25, 80 + 36, 208 -25, 122 + 36);
fill (100);
triangle (180-25, 118 + 36, 170- 25, 148 + 36, 197 - 25, 147 + 36);
fill (240);
ellipse(200- 25, 127 + 36, 10, 20);
fill(100, 100, 255);
rect (194- 25, 132 + 36, 15, 10);
fill (200, 150, 50);
rect(130, 184, 50, 5); }
//when the timer is done, empty the food bin
else {isFoodFilled = false;}
}
//method to draw the neutral head with the blink
void drawNeutralHead(){
//get the value of milliseconds
milliseconds2 = (int) millis() - reset;
//draw the head
noStroke();
fill(100, 100, 255);
quad(185, 143, 208, 146, 206, 160, 189, 162);
ellipse(195, 130, 40, 40);
triangle (178, 119, 220, 80, 208, 122);
fill (100);
triangle (180, 118, 170, 148, 197, 147);
fill (240);
//have the eyes blink randomly
//if it blinks, reset the millisecond counter to 0, and generate a new random number
if (milliseconds2 >= randomTime){
//if the timer is true, draw the eyes for the animation. when the timer is over, THEN make alterations to variables.
if (timer(5) == true){ellipse (200, 127, 10, 3);}
else{randomTime = (int)random(1000, 5000);
reset = reset + milliseconds2 + 5;}}
//if it is not blinking, draw the eye normally
else{ellipse(200, 127, 10, 20); }}
//method to draw the head looking at the balls
void drawMotionHead(){
//draw the static neck
noStroke();
fill(100, 100, 255);
quad(185, 143, 208, 146, 206, 160, 189, 162);
ellipse(195, 130, 40, 40);
//draw the head looking depending on which ball is moving
if (ball1){ // the red one
triangle (178, 119, 220, 80, 208, 122);
fill(100);
triangle(160, 146, 179, 119, 185, 146);
fill (255);
ellipse(190, 127, 10, 20); }
if (ball2){ // the green one
triangle (213, 126, 233, 167, 206, 146);
fill (100);
triangle(167, 101, 174, 130, 192, 110);
fill (255);
ellipse (189, 125, 10, 20);}
if (ball3){ // the blue one
triangle (178, 118, 164, 160, 194, 145);
fill (100);
triangle (201, 109, 227, 105, 213, 135);
fill (255);
ellipse (192, 120, 10, 20); }
if (ball4){ //the yellow one
triangle (200, 110, 156, 99, 178, 135);
fill (100);
triangle (209, 118, 233, 131, 208, 144);
fill (255);
ellipse (202, 126, 10, 20);
}
}
//method to draw the cage
void cageDraw(){
strokeWeight (3);
stroke(100);
fill(100);
for (int i = 0; i < 7; i++){
line (80 + (40*i), 40, 80 + (40*i), 320); }
strokeWeight(6);
line (30, 20, 30, 400);
line (30, 20, 200, 20);
line (200, 20, 200, 40);
line (80, 40, 320, 40);
rect(80, 320, 240, 20);
quad(60, 360, 80, 340, 320, 340, 340, 360); }
//draw the balls and chords
void drawBalls(){
stroke(0);
strokeWeight(2);
line(100, 40, ball1x, ball1y);
line(150, 40, ball2x, ball2y);
line(300, 40, ball3x, ball3y);
line(270, 40, ball4x, ball4y);
ellipseMode(CENTER);
noStroke();
fill(255, 0, 0);
ellipse(ball1x, ball1y, 20, 20);
fill (0, 255, 0);
ellipse(ball2x, ball2y, 20, 20);
fill(0, 0, 255);
ellipse(ball3x, ball3y, 20, 20);
fill (255, 255, 0);
ellipse(ball4x, ball4y, 20, 20);}
//method to draw the bg
void drawBG(){
//draw the bg
background(232, 210, 215);
fill(100, 0, 0);
noStroke();
rect(0, 300, 400, 100);}
//method to draw static objects
void bodyDraw(){
//draw the birds static body- wing, base, wing
noStroke();
fill(80, 80, 255);
quad(175, 160, 170, 190, 190, 235, 195, 190);
fill(100, 100, 255);
quad(182, 162, 210, 158, 225, 220, 190, 220);
ellipse(205, 215, 30, 35);
quad(200, 200, 200, 255, 235, 295, 235, 242);
fill(80, 80, 255);
quad(210, 150, 200, 186, 228, 230, 232, 190);
//draw the birds pedestal and the food box
stroke(100);
strokeWeight(9);
line(150, 250, 150, 320);
line(150, 250, 230, 250);
strokeWeight(4);
stroke(150);
fill(180);
rect(130, 190, 50, 30);
//if the mouse is hovering over the food box, light it up
if (mouseX > 130 && mouseX < 180 && mouseY > 190 && mouseY < 220){
fill (255, 50);
rect(130, 190, 50, 30);}
//draw the feet
noStroke();
fill(125);
quad(195, 225, 190, 240, 195, 246, 200, 228);
quad(208, 224, 207, 244, 215, 245, 215, 224);
ellipse(190, 248, 18, 18);
ellipse(212, 248, 18, 18); }
//if the mouse is clicked on the food bin, fill it with food
void mousePressed(){
if (mouseX > 130 && mouseX < 180 && mouseY > 190 && mouseY < 220){
isFoodFilled = true; }}
//if the mouse is dragged where a ball is, move the ball around within a restricted domain and return a boolean that says
// that the ball is, indeed, being moved.
void mouseDragged(){
if (mouseX>80 && mouseX < 120 && mouseY>130 && mouseY< 170){
ball1x = mouseX;
ball1y = mouseY;
ball1= true;
ball2 = false;
ball3 = false;
ball4 = false; }
if(mouseX>130 && mouseX < 170 && mouseY>60 && mouseY< 100){
ball2x = mouseX;
ball2y = mouseY;
ball1= false;
ball2 = true;
ball3 = false;
ball4 = false;}
if(mouseX>280 && mouseX < 320 && mouseY>50 && mouseY< 90){
ball3x = mouseX;
ball3y = mouseY;
ball1= false;
ball2 = false;
ball3 = true;
ball4 = false;}
if(mouseX>250 && mouseX < 290 && mouseY>100 && mouseY< 140){
ball4x = mouseX;
ball4y = mouseY;
ball1= false;
ball2 = false;
ball3 = false;
ball4 = true;}}
//when the mouse is released, reset the balls to their normal location
void mouseReleased(){
ball1x = 100;
ball1y = 150;
ball2x= 150;
ball2y= 80;
ball3x = 300;
ball3y = 70;
ball4x = 270;
ball4y = 120;
ball1 = false;
ball2 = false;
ball3 = false;
ball4 = false;
}
//create a timer that lasts for a specified amount of time in methods it's used in
boolean timer(int length){
milliseconds = millis() - reset2;
if (millis() - milliseconds < length){
reset2= reset2 + 1;
return true;}
else {reset2 = 0;
return false;}}