Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/* Interactive Toy
 Oct. 1st, 2018
 
 "Complete the Cupcake"
 by Liana Valdez
 
 ABOUT:
 You've been asked to finish making some cupcakes. 
 Whether you succeed or fail- and how badly- is up to you.
 
 HOW TO PLAY:
 Add ingredients to the bowl by clicking on them.
 The ingredients that can be added are milk, an egg, dog food, and the plant.
 Clicking the bake button will show the result of the mixture.
 There is one way to succeed and there are six ways to fail.
 In all cases, text will appear commenting on the user's results.
 
 TO SUCCEED, add milk and an egg to the bowl and click the bake button.
 
 TO FAIL, do any of the following and click the bake button:
 1. Add the dog food and the plant 
 (does not matter if milk and/or egg is added)
 2. Add the dog food, but not the plant 
 (does not matter if milk and/or egg is added)
 3. Add the plant, but not the dog food
 (does not matter if milk and/or egg is added)
 4. Add milk, but do not add anything else
 5. Add the egg, but do not add anything else
 6. Add no ingredients
 
 ADDITIONAL CREDITS:
 Code for mousePressed within constraints (used for clicking on ingredients)
 adapted from user JohnG's code in this Processing.org forum:
 https://processing.org/discourse/beta/num_1238661349.html */

//DECLARE VARIABLES
//Wallpaper stripes X-coordinates
int darkX = 0;
int lightX = 30;

//Ingredients
boolean dogFood = false;
boolean egg = false;
boolean milk = false;
boolean plant = false;

//Bake button
boolean button = false;

//Result screens
boolean success = false;
boolean failure = false;

//Sprinkle colours + Fail bake colour
int colour1 = int(random (0, 255));
int colour2 = int(random (0, 255));
int colour3 = int(random (0, 255));
int colour4 = int(random (0, 255));
int colour5 = int(random (0, 255));
int colour6 = int(random (0, 255));
int colour7 = int(random (0, 255));
int colour8 = int(random (0, 255));
int colour9 = int(random (0, 255));
int colour10 = int(random (0, 255));
int colour11 = int(random (0, 255));
int colour12 = int(random (0, 255));
int colour13 = int(random (0, 255));
int colour14 = int(random (0, 255));
int colour15 = int(random (0, 255));

//SETUP
//Set frame rate, size of window, & circle mode
void setup() { 
  frameRate(60);
  size(400, 400);
  ellipseMode(RADIUS);

  //PRINT WELCOME COMMENT
  welcomeComment();
}

//DRAW
void draw() {

  //CHECK IF RESULT HAS BEEN DETERMINED
  if (success == true) {
    drawSuccess();
  } else if (failure == true) {
    drawFailure();

    //OTHERWISE, Draw kitchen
  } else {
    //Draw background (wallpaper, window, counter, floor, table)
    drawWallpaper();
    drawWindow();
    drawCounter();
    drawFloor();
    drawTable();

    //Draw bowl and ingredients
    drawBowl();
    drawDogFood();
    drawEggs();
    drawPlant();
    drawMilk();

    //Draw bake button
    drawBakeButton();

    //CHECK IF INGREDIENTS ARE CLICKED
    //Check if milk is clicked 
    clickMilk();
    if (milk == true) {
      drawMilkInBowl();
    }
    //Check if egg is clicked 
    clickEgg();
    if (egg == true) {
      drawEggInBowl();
    }
    //Check if dog food is clicked
    clickDogFood();
    if (dogFood == true) {
      drawDogFoodInBowl();
    }
    //Check if plant is clicked
    clickPlant();
    if (plant == true) {
      drawPlantInBowl();
    }
    //Check if bake button is clicked 
    clickButton();
    if (button == true) {
      //PRINT RESULT COMMENT
      resultComment();

      //CHECK CONDITIONS FOR RESULTS
      //If milk and egg are the only ingredients in bowl, trigger SUCCESS
      if (milk == true && egg == true && dogFood == false && plant == false) {
        success = true;

        //OTHERWISE, trigger FAILURE
      } else {
        failure = true;
      }
    }
  }
}

//FUNCTIONS
//WELCOME COMMENT
void welcomeComment() {
  println("Hey, thanks for taking over to finish making these cupcakes.");
  println("Don't worry, it's really unlikely you'll mess 'em up.");
  println("I'll be back when they're done. See you later!");
}

//DRAWS THE KITCHEN
//Draws the wallpaper
void drawWallpaper() {
  while (darkX <400 && lightX <400)
  {
    noStroke();
    fill(239, 212, 67);
    rect(darkX, 0, 30, 400); 
    darkX  = darkX  + 60;
    fill(247, 235, 170);
    rect(lightX, 0, 30, 400);
    lightX = lightX + 60;
  }
}
//Draws the window
void drawWindow() {
  fill(244, 242, 237);
  rect(140, 10, 120, 70);
  fill(151, 220, 229);
  rect(150, 20, 40, 20);
  rect(210, 20, 40, 20);
  rect(150, 50, 40, 20);
  rect(210, 50, 40, 20);
}
//Draws the back counter
void drawCounter() {
  fill(193, 179, 153);
  rect(0, 90, 400, 60);
  fill(122, 112, 93);
  rect(0, 150, 400, 50);
  fill(137, 127, 96);
  rect(0, 150, 60, 50);
  rect(120, 150, 60, 50);
  rect(240, 150, 60, 50);
  rect(360, 150, 60, 50);
}
//Draws the floor
void drawFloor() {
  fill(244, 242, 237);
  rect(0, 200, 400, 70);
}
//Draws the table
void drawTable() {
  fill(178, 156, 94);
  rect(0, 270, 400, 160);
}
//Draws the bowl
void drawBowl() {
  fill(62, 139, 239);
  ellipse(200, 300, 110, 85);
  fill(114, 164, 229);
  ellipse(200, 275, 110, 60);
  fill(232, 223, 192);
  ellipse(200, 285, 110, 50);
}

//DRAWS INGREDIENTS
//Draws the dog food
void drawDogFood() {
  fill(219, 72, 52);
  rect(20, 220, 40, 20);
  //First row
  fill(119, 93, 46);
  ellipse(25, 220, 5, 5);
  ellipse(35, 220, 5, 5);
  ellipse(45, 220, 5, 5);
  ellipse(55, 220, 5, 5);
  //Second row
  ellipse(30, 210, 5, 5);
  ellipse(40, 210, 5, 5);
  ellipse(50, 210, 5, 5);
  //Third row
  ellipse(35, 200, 5, 5);
  ellipse(45, 200, 5, 5);
  //Top
  ellipse(40, 190, 5, 5);
}
//Draws the eggs
void drawEggs() {
  fill(163, 159, 151);
  rect(40, 100, 60, 40);
  fill(122, 121, 112);
  rect(40, 130, 60, 10);
  fill(244, 242, 237);
  ellipse(50, 120, 5, 7);
  ellipse(70, 120, 5, 7);
  ellipse(90, 120, 5, 7);
  ellipse(50, 100, 5, 7);
  ellipse(70, 100, 5, 7);
  ellipse(90, 100, 5, 7);
}
//Draws the plant
void drawPlant() { 
  //Stem
  stroke(59, 145, 20);
  strokeWeight(3);
  line(200, 40, 200, 100);
  line(180, 60, 200, 80);
  line(220, 60, 200, 80);
  //Leaves
  noStroke();
  fill(125, 196, 66);
  ellipse(200, 40, 7, 7);
  ellipse(180, 60, 7, 7);
  ellipse(220, 60, 7, 7);
  //Pot
  noStroke();
  fill(221, 160, 68);
  rect(180, 100, 40, 30);
  fill(193, 121, 27);
  rect(180, 93, 40, 10);
}
//Draws the milk
void drawMilk() {
  fill(255);
  rect(310, 80, 40, 60);
  fill(34, 103, 249);
  rect(310, 70, 40, 10); 
  rect(310, 100, 40, 20);
}
//Draws the bake button
void drawBakeButton() {
  stroke(76, 55, 150);
  fill(122, 102, 196);
  rect(7, 350, 75, 30);
  //B
  ellipse(20, 360, 6, 5);
  ellipse(20, 370, 6, 5);
  strokeWeight(5);
  line(15, 356, 15, 374);
  //A
  strokeWeight(3);
  line(37, 357, 30, 374);
  line(37, 357, 40, 374);
  line(35, 370, 37, 370);
  //K
  line(50, 357, 50, 374); 
  line(50, 367, 60, 357);
  line(50, 367, 60, 374);
  //E
  line(67, 357, 67, 374);
  line(67, 357, 75, 357);
  line(67, 365, 75, 365);
  line(67, 374, 75, 374);
  noStroke();
}

//CHECK IF MOUSE CLICKS ON INGREDIENTS OR BUTTON
//Click on milk
void clickMilk() {
  if (mousePressed && mouseX >310 && mouseX<350 && mouseY>70 && mouseY<140 && milk == false) {
    milk = true;
  }
}
//Click on eggs
void clickEgg() {
  if (mousePressed && mouseX >40 && mouseX<100 && mouseY>90 && mouseY<140 && egg == false) {
    egg = true;
  }
}
//Click on dog food
void clickDogFood() {
  if (mousePressed && mouseX >20 && mouseX<60 && mouseY>180 && mouseY<240 && dogFood == false) {
    dogFood = true;
  }
}
//Click on plant
void clickPlant() {
  if (mousePressed && mouseX >173 && mouseX<227 && mouseY>33 && mouseY<130 && plant == false) {
    plant = true;
  }
}
//Click on button
void clickButton() {
  if (mousePressed && mouseX >7 && mouseX<82 && mouseY>350 && mouseY<380 && button == false) {
    button = true;
  }
}

//DRAW INGREDIENTS IN BOWL
//Draws milk in bowl
void drawMilkInBowl() {
  fill(237, 236, 234);
  ellipse(200, 295, 80, 40);
}
//Draws egg in bowl
void drawEggInBowl() {
  fill(255);
  ellipse(200, 295, 40, 20);
  fill(255, 227, 22);
  ellipse(200, 295, 17, 10);
}
//Draws dog food in bowl
void drawDogFoodInBowl() {
  fill(119, 93, 46);
  ellipse(100, 270, 10, 10);
  ellipse(120, 250, 10, 10);
  ellipse(140, 260, 10, 10);
  ellipse(150, 290, 10, 10);
  ellipse(190, 270, 10, 10);
}
//Draws plant in bowl
void drawPlantInBowl() {
  stroke(59, 145, 20);
  strokeWeight(7);
  line(250, 300, 300, 220);
  noStroke();
  fill(125, 196, 66);
  ellipse(300, 220, 30, 30);
}

//DRAW RESULT SCREENS
//Success screen
void drawSuccess() {
  //Draw background
  fill(134, 233, 244);
  rect(0, 0, 400, 400);

  //Draw cupcake icing
  fill(247, 155, 242);
  ellipse(200, 210, 90, 90);
  //Draw paper
  fill(244, 234, 93);
  rect(110, 220, 180, 100);
  fill(216, 214, 93);
  rect(110, 220, 30, 100);
  rect(170, 220, 30, 100);
  rect(230, 220, 30, 100);
  //Draw Cherry
  stroke(8, 178, 42);
  strokeWeight(4);
  noFill();
  arc(270, 120, 70, 65, PI, PI+QUARTER_PI);
  noStroke();
  fill(198, 1, 67);
  ellipse(200, 120, 25, 25);
  fill(255);
  ellipse(210, 110, 5, 5);

  //Draw Sprinkles, Randomize colours
  strokeWeight(5);
  stroke(colour1, colour2, colour3);
  line(140, 210, 150, 190);
  stroke(colour4, colour5, colour6);
  line(185, 200, 210, 195);
  stroke(colour7, colour8, colour9);
  line(240, 210, 260, 190);
  stroke(colour10, colour11, colour12);
  line(160, 165, 185, 175);
  stroke(colour13, colour14, colour15);
  line(230, 160, 240, 180);
  noStroke();
}

//Failure screen
void drawFailure() {
  //Draw background
  fill(118, 130, 113);
  rect(0, 0, 400, 400);

  //Draw flop, Randomize colours
  fill(colour1, colour2, colour3);
  ellipse(200, 210, 90, 55);
  ellipse(135, 240, 75, 65);
  ellipse(300, 350, 30, 15);
  ellipse(280, 365, 20, 10);

  //Draw paper
  fill(244, 234, 93);
  rect(110, 220, 180, 100);
  fill(216, 214, 93);
  rect(110, 220, 30, 100);
  rect(170, 220, 30, 100);
  rect(230, 220, 30, 100);
}

//COMMENTS BASED ON THE RESULTS
void resultComment() {
  //SUCCESS
  //Milk and egg
  if (milk == true && egg == true && dogFood == false && plant == false) {
    println("Fantastic! Thanks for helping out. I knew I could count on you.");

    //FAILURES
    //1. Dog food and plant
  } else if (dogFood == true && plant == true) {
    println("I came as soon as I heard the explosion. What did you do to the cupcakes?! ");

    //2. Dog food, no plant
  } else if (dogFood ==true && plant == false) {
    println("This is awful... Maybe I can feed it to the dog when you're not looking.");

    //3. Plant, no dog food
  } else if (plant == true && dogFood == false) {
    println("Did...did I just bite into a leaf?");

    //4. Milk and nothing else
    //Note: "Oeuf", pronounced similarly to "Oof", means "Egg" in French.
  } else if (dogFood == false && plant == false && milk == true && egg == false) {
    println("Oeuf! Well, that's an egg on your face. You forgot to add something...");

    //5. Egg and nothing else
  } else if (dogFood == false && plant == false && milk == false && egg == true) {
    println("If you're lactose intolerant, I understand. If you aren't, you forgot to add something...");

    //6. No ingredients added
  } else {
    println("Did you just throw this into the oven without adding the ingredients? You had one job!");
  }
}