/** * Cutting cake * by Daniel Smith * * A knife moves up and down the y-axis (controlled by mouseY). * When the user clicks, a slice of cake is 'drawn' onto the plate. * The program terminates there.. */ void setup(){ size(400, 400); } void draw(){ /*Background*/ //The wall fill(255, 222, 159); stroke(0); rect(0, 0, 400, 270); //Lamp and Light fill(245, 253, 25, 31); noStroke(); quad(150, 40, 250, 40, 400, 270, 0, 270); //Light fill(255); noStroke(); ellipse(200, 40, 33, 33); //bulb fill(255, 245, 205); stroke(255, 226, 149); arc(200, 40, 100, 100, 3.14, 6.28); // Lamp Shade (ellipse, start (radians), end(radians)) //The table / surface fill(131, 165, 175); stroke(0); rect(0, 270, 400, 130); //The plate fill(227); rect(270, 370, 80, 5); fill(255); quad(240, 350, 380, 350, 360, 370, 260, 370); fill(218); ellipseMode(CORNER); //Remember: ellipse's default mode is CENTER, unlike rect.. ellipse(240, 340, 140, 20); ellipseMode(CENTER); //Since I rather use CENTER for the remainder of the program) /*I divide the cake and knife into several layers*/ //Layer 0 (Icing): fill(161, 255, 252); //Light blue stroke(111, 223, 255); //Slightly darker light blue triangle(130, 210, 20, 260, 240, 260); //Layer 1 (Sprinkles): noStroke(); fill(255, 173, 239); //Pink ellipse(130, 220, 10, 5); ellipse(90, 240, 10, 5); ellipse(50, 260, 10, 5); ellipse(130, 240, 10, 5); ellipse(90, 260, 10, 5); ellipse(170, 240, 10, 5); ellipse(130, 260, 10, 5); ellipse(170, 260, 10, 5); ellipse(210, 260, 10, 5); fill(244, 255, 173); //Yellow ellipse(110, 230, 10, 5); ellipse(70, 250, 10, 5); ellipse(150, 230, 10, 5); ellipse(110, 250, 10, 5); ellipse(150, 250, 10, 5); ellipse(190, 250, 10, 5); //Layer 2 (Knife): //Blade stroke(153); fill(173); triangle(130, mouseY-90, 155, mouseY-70, 260, mouseY-110); fill(195); quad(155, mouseY-70, 230, mouseY-70, 265, mouseY-101, 265, mouseY-111); //Something's messed up about the coordinates here, and on my graph... //Handle fill(67); //almost black rect(265, mouseY-111, 60, 10); rect(305, mouseY-111, 20, 20); fill(255, 25, 41); //red basically rect(275, mouseY-111, 10, 5); fill(173); rect(285, mouseY-111, 10, 5); //Layer 3 (Cake[Base]): fill(255, 243, 195); //I like vanilla cake stroke(255, 226, 149); quad(20, 260, 20, 320, 130, 380, 130, 320); quad(240, 260, 240, 320, 130, 380, 130, 320); //Layer 4 (Icing[Sides]): fill(161, 255, 252); //Light blue stroke(111, 223, 255); //Slightly darker light blue ellipse(30, 280, 20, 40); ellipse(50, 290, 20, 40); ellipse(70, 300, 20, 40); ellipse(90, 310, 20, 40); ellipse(110, 320, 20, 40); ellipse(130, 330, 20, 40); ellipse(150, 320, 20, 40); ellipse(170, 310, 20, 40); ellipse(190, 300, 20, 40); ellipse(210, 290, 20, 40); ellipse(230, 280, 20, 40); //Layer 5 (Icing[Top]): noStroke(); rect(20, 260, 221, 15); triangle(20, 275, 130, 330, 240, 270); //Layer 6 (More Sprinkles on Top): fill(255, 173, 239); //Pink ellipse(90, 280, 10, 5); ellipse(130, 280, 10, 5); ellipse(170, 280, 10, 5); ellipse(130, 300, 10, 5); fill(244, 255, 173); //Yellow ellipse(70, 270, 10, 5); ellipse(110, 270, 10, 5); ellipse(110, 290, 10, 5); ellipse(150, 270, 10, 5); ellipse(150, 290, 10, 5); ellipse(190, 270, 10, 5); } void mousePressed(){ /*When the mouse is clicked, a piece of cake appears on the cake*/ frameRate(2); //The program will appear to stop once you've 'cut' the cake. fill(255, 243, 195); //I like vanilla cake stroke(255, 226, 149); rect(260, 310, 100, 40); fill(255); rect(260, 327, 100, 5); //Icing fill(161, 255, 252); noStroke(); //stroke(111, 223, 255); rect(260, 310, 100, 5); rect(357, 310, 5, 40); triangle(260, 310, 330, 280, 362, 310); //Sprinkles fill(255, 173, 239); ellipse(320, 290, 10, 5); ellipse(340, 300, 10, 5); fill(244, 255, 173); ellipse(300, 300, 10, 5); } //Build Successful