/*Interactive Toy
*IMC Assignement #2
*Gabby Simpson
*5 October,2015
*
*Instructions
* 1.mouseover a firework to connect it to the switch
* 2.once you have connected the fireworks you want, click anywhere to ignite them
* 3.mouseover the reset button in the top right to disconnect all the fireworks
*/
//firework locations
int fWY = 320;
int fW1X = 20;
int fW2X = 70;
int fW3X = 120;
int fW4X = 350;
int fW5X = 300;
int fW6X = 250;
//variables to keep track of which fireworks are connected
boolean f1 = false;
boolean f2 = false;
boolean f3 = false;
boolean f4 = false;
boolean f5 = false;
boolean f6 = false;
int count = 0;
//setup
void setup () {
rectMode(CORNERS);
ellipseMode(CENTER);
size(400, 400);
noStroke();
noSmooth();
background(0);
//ground
fill(125, 75, 25);
rect(0, 360, 400, 400);
f1 = false;
f2 = false;
f3 = false;
f4 = false;
f5 = false;
f6 = false;
drawSky();
count = 0;
}
//draw
void draw () {
selectFW();
drawFW();
//ignites the fireworks
if (mousePressed) {
ignite();
}
//resets the fireworks
if (mouseX > 350 && mouseX < 400 && mouseY < 50 && mouseY > 0 ){
setup();
}
//reset button
noStroke();
fill(255,255,255);
ellipse(375,25,25,25);
fill(0);
ellipse(375,25,15,15);
rect(370,25,380,50);
fill(255,255,255);
triangle(370,25,370,40,380,33);
}
//function to ignite fireworks
void ignite() {
if (f1 == true) {
stroke(0, 255, 0);
strokeWeight(4);
line(35, 80, 35, 0);
line(35, 80, 35, 160);
line(35, 80, 0, 80);
line(35, 80, 115, 80);
line(35, 80, 85, 30);
line(35, 80, 85, 130);
line(35, 80, 0, 130);
line(35, 80, 0, 30);
fill(0);
stroke(0);
ellipse(35, 80, 40, 40);
noFill();
ellipse(35, 80, 80, 80);
ellipse(35, 80, 120, 120);
}
if (f2 == true) {
stroke(255, 150, 0);
strokeWeight(4);
line(85, 140, 85, 20);
line(85, 140, 85, 260);
line(85, 140, 0, 140);
line(85, 140, 205, 140);
line(85, 140, 125, 100);
line(85, 140, 125, 180);
line(85, 140, 45, 100);
line(85, 140, 45, 180);
fill(0);
stroke(0);
ellipse(85, 140, 40, 40);
noFill();
ellipse(85, 140, 80, 80);
ellipse(85, 140, 120, 120);
}
if (f3 == true) {
noStroke();
fill(255, 0, 255);
ellipse(135, 20, 20, 20);
ellipse(135, 80, 20, 20);
ellipse(135, 140, 20, 20);
ellipse(135, 200, 20, 20);
ellipse(135, 260, 20, 20);
}
if (f4 == true) {
stroke(255, 0, 0);
strokeWeight(4);
line(335, 60, 335, 0);
line(335, 60, 335, 120);
line(335, 60, 395, 60);
line(335, 60, 275, 60);
line(335, 60, 400, 30);
line(335, 60, 400, 90);
line(335, 60, 275, 90);
line(335, 60, 275, 30);
fill(0);
stroke(0);
ellipse(335, 60, 40, 40);
noFill();
ellipse(335, 60, 80, 80);
ellipse(335, 60, 120, 120);
}
if (f5 == true) {
noStroke();
fill(0, 0, 255);
ellipse(315, 20, 20, 20);
ellipse(315, 80, 20, 20);
ellipse(315, 140, 20, 20);
ellipse(315, 200, 20, 20);
ellipse(315, 260, 20, 20);
}
if (f6 == true) {
noStroke();
fill(255, 255, 0);
ellipse(265, 20, 20, 20);
ellipse(265, 80, 20, 20);
ellipse(265, 140, 20, 20);
ellipse(265, 200, 20, 20);
ellipse(265, 260, 20, 20);
}
}
void drawFW() {
noStroke();
//switch
fill(15, 15, 75);
rect(195, 351, 205, 330);
rect(180, 329, 220, 339);
fill(30, 30, 100);
rect(180, 390, 220, 350);
//fireworks left
fill(255, 50, 20);
rect(fW1X, fWY+60, fW1X+30, fWY);
triangle(15, 320, 55, 320, 35, 300);
rect(fW2X, fWY+60, fW2X+30, fWY);
triangle(65, 320, 105, 320, 85, 300);
rect(fW3X, fWY+60, fW3X+30, fWY);
triangle(115, 320, 155, 320, 135, 300);
//fireworks right
rect(fW4X, fWY+60, fW4X+30, fWY);
triangle(385, 320, 345, 320, 365, 300);
rect(fW5X, fWY+60, fW5X+30, fWY);
triangle(335, 320, 295, 320, 315, 300);
rect(fW6X, fWY+60, fW6X+30, fWY);
triangle(285, 320, 245, 320, 265, 300);
}
//function to connect fireworks
void selectFW() {
fill(0, 0, 0);
//firework 1
if (mouseX > fW1X && mouseX < (fW1X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(35, 380, 36, 390);
rect(35, 390, 200, 389);
f1 = true;
}
//firework 2
if (mouseX > fW2X && mouseX < (fW2X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(85, 380, 86, 387);
rect(85, 387, 200, 386);
f2 = true;
}
//firework 3
if (mouseX > fW3X && mouseX < (fW3X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(135, 380, 136, 384);
rect(135, 384, 200, 383);
f3 = true;
}
//firework 4
if (mouseX > fW4X && mouseX < (fW4X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(365, 380, 364, 390);
rect(365, 390, 200, 389);
f4 = true;
}
//firework 5
if (mouseX > fW5X && mouseX < (fW5X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(315, 380, 314, 387);
rect(315, 387, 200, 386);
f5 = true;
}
//firework 6
if (mouseX > fW6X && mouseX < (fW6X+30) && mouseY < (fWY+60) && mouseY > fWY) {
rect(265, 380, 264, 384);
rect(265, 384, 200, 383);
f6 = true;
}
}
//function to randomly place 30 stars
void drawSky(){
strokeWeight(1);
while(count < 30){
stroke(255);
point(random(20,380), random(20,380));
count++;
}
}