Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/************************************************************************************
 CANADA DAY
 By: Liam McAlinden
 Its Canada Day, move the mouse to set the location for the Fireworks to 
 launch and enjoy the show
 
 Intro to Media Computation
 October 19th 2016
 
 /////////////////////////////////////////////////////////
 Disclaimer, some of the code that is used in this program
 have been borrowed from the IMC website folder 
 Adventures in code fireworks folder 
 But have been modified to make them my own 
 the ExplosionTime tab was taken from the IMC website folder adventures in code, 
 fireworks folder which was copied from Daniel Shiffmans Learning processing.
 *************************************************************************************/



//Creates an Array list for the Stars so I can make Multiple to
//avoid drawing 100 stars 
Stars [] Galaxy = new Stars [1000];
//Creates an Array list for the fireworks 
ArrayList<Fireworks> Explosion = new ArrayList<Fireworks> ();
//Creates gravity so the particles can fall at certain speeds
PVector gravity = new PVector  (-0.0001, 0.0001);

int exploisonSize = 100; // how particles I will have in this program 

float ExplosionTime=.5;// how long each explosion will be
float ExplosionStartTime;


void setup () {
  size (400, 600);
  ExplosionStartTime = millis(); 
  // the start time for the explosion
  //when the prgram starts
  rectMode (CORNER);
  ellipseMode (CENTER);
  // if the stars that are dran equal less than 1000 more will be drawn until then
  for (int i = 0; i < 1000; i++) {
    Galaxy[i] = new Stars();
    colorMode (HSB, 255);// this code was borrowed form the IMC Website, Adventures in code Firworks Tab
  }
}
void draw () {
  background (10, 0, 41);
  // if the stars that are dran equal less than 1000 more will be drawn until then and prints
  // i added print to make sure that it worked
  for (int i = 0; i < 1000; i++) {
    //println(i);
    Galaxy[i].drawStar();
  }
  //trees there just trees 
  fill (0, 20, 25);
  triangle (0, 300, 30, 450, -20, 450);
  triangle (40, 320, 60, 450, 20, 450);
  triangle (70, 300, 40, 450, 90, 450);
  triangle (110, 320, 140, 450, 90, 450);

  triangle (140, 300, 120, 450, 160, 450);
  triangle (160, 320, 130, 450, 170, 450);
  triangle (180, 320, 160, 450, 200, 450);
  triangle (210, 300, 200, 450, 220, 450);

  triangle (220, 300, 215, 450, 225, 450);
  triangle (250, 330, 230, 450, 270, 450);
  triangle (270, 320, 260, 450, 290, 450);
  triangle (300, 300, 140, 450, 330, 450);

  triangle (320, 300, 30, 450, 330, 450);
  triangle (360, 310, 60, 450, 370, 450);
  triangle (380, 320, 360, 450, 400, 450);
  triangle (400, 340, 140, 450, 450, 450);
  //hills
  fill (0, 20, 15);
  ellipse (0, 380, 230, 100);
  ellipse (50, 390, 230, 100);
  ellipse (140, 390, 230, 100);
  ellipse (340, 390, 230, 100);
  //ground
  fill (0, 38, 27);
  rect (0, 400, 400, 300);


// this is for the particle explosion, and if the start time is less than the explosion time 
// it will create the explosion

// this code was borrowed form the IMC Website, Adventures in code Fireworks Tab
  if (millis()-ExplosionStartTime>ExplosionTime*1000.) {
    // will generate a random colour for the fireworks
    color explosionColor = color(random(0, 255), 255, 255);
    for (int i=0; i<exploisonSize; i++) {
      // wherever the mouse is located that is were the explosions will happen 
      Explosion.add(new Fireworks(mouseX, mouseY, explosionColor));
    }
    ExplosionStartTime = millis ();
  }
// this code is for the duration of time the explosion lasts
  for (int i=Explosion.size ()-1; i>=0; i--) {
    Fireworks fireworks = Explosion.get(i);
    fireworks.refresh();
    if (fireworks.explosionTime.isFinished()) {
      Explosion.remove(i);// if the time is up than the explosion is removed 
    }
  }

  for (int i=0; i<Explosion.size(); i++) {
    Fireworks fireworks = Explosion.get(i);
    fireworks.display();
  }
}
//learning processing
//Daniel Shiffman
// http://www.learningprocessing.com

// Example 10-5: Object- orientated timer

// this code was borrowed from the IMC Website, Adventures in Code fireworks tab
// which was borrowed from daniel shiffmans Learning processing
class Timer {
  
// savedTime is the start time, total time is how much it has gone on and how long it lasts
  int savedTime; 
  int totalTime;
  Timer(int tempTotalTime) {
    totalTime = tempTotalTime;
  } 
  
  void start() {
    // when the time starts it will keep the current time in milliseconds
    savedTime = millis();
  }

  // the boolean is finished will activate when the 1000 seconds goes by 
  boolean isFinished() { 
    
    // this will check how much time has gone by 
    int passedTime = millis()- savedTime;
    if (passedTime > totalTime) {
      return true;
    } else {
      return false;
    }
  }
}
class Fireworks 
{
  //Fireworks location: creates the location for the particles 
  PVector location = new PVector ();

  //Fireworks velocity: creates the speed of the particles
  PVector velocity = new PVector ();

  //Fireworks size:the size of the particles that are in the explosion 
  float size = random(0, 5);

  //Color of the explosion: what the colour will be
  color explosionColor;

  //Duration of explosion: how long the explosion will last 
  int ExplosionDuration = 10;

  //Declares a time: declares timer in the next tab 
  Timer explosionTime;

  //Class constructor: creates that class of the particles so that they are able to be formed
  // also designs how the particles will act 
  Fireworks (float x, float y, color paramColor) { // colour and locaiton
    location.x= x;
    location.y= y;
    explosionColor = paramColor;
    velocity.x= random (-2, 2);// the speed of the x and y 
    velocity.y = random (-2, 2);
    explosionTime = new Timer (ExplosionDuration*100); // how long the explosion lasts 
    explosionTime.start();
  }

  //Refersh fireworks: updates the fireworks in the draw 
  void refresh () { 
    velocity.add(gravity);
    location.add(velocity);
    display();
  }

  //Displays fireworks :) :
  void display () {
    fill (explosionColor);
    ellipse (location.x, location.y, size, size);
  }
}
class Stars {
  //Position vector: the position of the stars 
  PVector starPosition = new PVector (0, 0);

  public Stars ()
  {
    // the x and y poosition of the stars 
    starPosition.x = random (0, 400);
    starPosition.y = random (0, 400);
  }
  void drawStar () {
    // draws the stars 
    noStroke ();
    fill (255, random(0, 255));
    ellipse (starPosition.x, starPosition.y, 2, 2);
  }
}