/* The Soft Serve Machine (Assignment 2) by Zach Strauss To use the machine, click the cone to place it in the middle of the machine and press a flavour select it. To put it in the cone, press the green button below the cone slot. Press the button on the right side of the machine to reset the machine. */ int flavour = 0; int coneTipX1 = 330; int coneTipY1 = 220; int coneTipX2 = 350; int coneTipY2 = 260; int coneTipX3 = 370; int coneTipY3 = 220; int coneBaseX = 330; int coneBaseY = 210; int coneBaseW = 40; int coneBaseH = 10; boolean coneReady = false; void setup() { size(400, 400); } void draw() { background(255, 224, 144); noStroke(); fill(88, 64, 41); rect(0, 360, 400, 400); frameRate(60); drawStaticMachine(); drawDynamicMachine(); drawCone(); } void drawStaticMachine() { //Drawing the Static Parts of the Ice Cream Machine using basic primitives.// stroke(1); strokeWeight(3); fill(175); rect(80, 340, 240, 60); rect(120, 100, 200, 240); rect(100, 60, 240, 40); rect(120, 40, 20, 20); rect(300, 40, 20, 20); rect(100, 20, 240, 20); rect(60, 100, 60, 20); rect(60, 120, 20, 20); rect(60, 300, 60, 20); rect(60, 280, 20, 20); rect(40, 140, 60, 140); rect(320, 260, 60, 20); rect(320, 120, 60, 60); fill(150); rect(180, 160, 60, 100); //Reset Button fill(100); rect(180, 260, 60, 20); //Vanilla Button fill(255); rect(60, 160, 20, 20); //Strawberry Button fill(247, 170, 225); rect(60, 200, 20, 20); //Chocolate Button fill(118, 67, 42); rect(60, 240, 20, 20); //Start Button fill(0, 255, 0); rect(200, 300, 20, 20); fill(0, 0, 0); rect(340, 140, 20, 20); fill(170); triangle(200, 160, 220, 160, 210, 180); } void drawDynamicMachine() { //Changes flavour based of off mouseClicked on buttons. // Declaration of required variables boolean vanillaButton = false; boolean strawberryButton = false; boolean chocolateButton = false; if (vanillaButton == true) { flavour = 1; } if (strawberryButton == true) { flavour = 2; } if (chocolateButton == true) { flavour = 3; } //Changes colour of machine tip based on what flavour was selected. if (flavour == 1 ) { fill(255); triangle(200, 160, 220, 160, 210, 180); } if (flavour == 2 ) { fill(247, 170, 225); triangle(200, 160, 220, 160, 210, 180); } if (flavour == 3 ) { fill(118, 67, 42); triangle(200, 160, 220, 160, 210, 180); } // If Else that checks whether or not the mouse is hovering over the reset// if ((mouseX >= 340) && (mouseX <= 360) && (mouseY >= 140 ) && (mouseY <= 160) ) { fill(255, 0, 0); rect(340, 140, 20, 20); } //Draws the alternating colour pattern at the top of the screen with loop.// //Declaration of the required variables.// int lightY = 40; int lightX = 140; int lightSpacing = 20; int lightEnd = 280; boolean lightColour = false; fill(255); while ( lightX <= lightEnd) { rect(lightX, lightY, 20, 20); lightX = lightX + lightSpacing; if (lightColour == false) { fill(255, 0, 0); lightColour = true; } else { fill(255); lightColour = false; } } } void drawCone() { fill(random(255), random(255), random(255)); triangle(coneTipX1, coneTipY1, coneTipX2, coneTipY2, coneTipX3, coneTipY3); rect(coneBaseX, coneBaseY, coneBaseW, coneBaseH); } void mouseClicked() { //Sets up the flavour buttons based on whether or not the user has clicked within //the buttons area. Sets up start and reset button. Programs the cone to move properly. //Flavour One if (mouseX >= 60 && mouseX <= 80 && mouseY >= 160 && mouseY <= 180) { flavour = 1; } //Flavour Two if (mouseX >= 60 && mouseX <= 80 && mouseY >= 200 && mouseY <= 220) { flavour = 2; } //Flavour Three if (mouseX >= 60 && mouseX <= 80 && mouseY >= 240 && mouseY <= 260) { flavour = 3; } //Reset Button. Resets cone position variables and flavour type. if (mouseX >= 340 && mouseX <= 360 && mouseY >= 140 && mouseY <= 160) { flavour = 0; coneTipX1 = 330; coneTipY1 = 220; coneTipX2 = 350; coneTipY2 = 260; coneTipX3 = 370; coneTipY3 = 220; coneBaseX = 330; coneBaseY = 210; coneBaseW = 40; coneBaseH = 10; coneReady = false; } //Cone Interaction if (mouseX >= 340 && mouseX <= 360 && mouseY >= 220 && mouseY <= 240) { coneTipX1 = 190; coneTipY1 = 220; coneTipX2 = 210; coneTipY2 = 260; coneTipX3 = 230; coneTipY3 = 220; coneBaseX = 190; coneBaseY = 210; coneReady = true; } //Start Button if (mouseX >= 200 && mouseX <= 220 && mouseY >= 300 && mouseY <= 320) { if (coneReady == true) { if (flavour == 1) { fill(255); ellipse(210, 210, 35, 35); frameRate(1); } if (flavour == 2) { fill(247, 170, 225); ellipse(210, 210, 35, 35); frameRate(1); } if (flavour == 3) { fill(118, 67, 42); ellipse(210, 210, 35, 35); frameRate(1); } } } }