Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*////////////////////////////////////////////////////////
 
 Andrew Taylor
 Interactive Toy
 
 Description:
 
 Press A = Ignites Fire
 Press S = Stops Fire
 Press W = Addes Stroke Effect
 Press E = Removes Stroke Effect
 
 "Located on the top left corner you will see a white bar. Please press this for further instructions.
 Welcome to our fire, have a seat and make your self cozy. Maybe this is a mediocre pixel fire place clone. 
 Maybe this exactly what you need to be watching at this moment. Who knows? 
 Id say take a deep breathe and soak in the stars, tell a few stories and enjoy this dynamic your are experiencing"
 
 
 
 ////////////////////////////////////////////////////////*/

// GLOBAL VARIABLES


// PIXEL SIZE - Defines the default size of the squares in the sketch
float pixelSpacingBig = 40;

// EMBERS -  These variables control the speed on the embers
float emberY = 400;
float emberSlow = .25;
float speed = random(.25);


// BOOLEANS - These variables are created for use within the conditional statements (Stroke / no Stroke, Fire / no Fire);
boolean a = true;
boolean s = false;
boolean w = true;
boolean e = false;

// CUSTOM FONT -  Loads the font used in the sketch. This font was made using the built in font creation tool in processing.
PFont font;





// SETUP - 
// Intializes size of sketch, 
// Removes stroke as default
// Initializes and loads custom font
// Prints message on startup

void setup() {

  size(800, 400);
  noStroke();
  font = loadFont ("fireFont.vlw");
  textFont (font);
  println( 
  
  
  "Located on the top left corner you will see a white bar. Please press this for further instructions. Welcome to our fire, have a seat and make your self cozy. Maybe this is a mediocre pixel fire place clone. Maybe this exactly what you need to be watching at this moment. Who knows? Id say take a deep breathe and soak in the stars, tell a few stories and enjoy this dynamic your are experiencing"
  
  );

}

// DRAW -
// Draws the background every frame
// Draws the functions called within draw every frame


void draw() {

  background(0);
  addStroke();
  grass();
  woodDark();
  woodBright();
  menu();
  woodEmbers();
  fireMediumOrange();
  fireBrightOrange();
  woodDarkBottomBorder();
  fireYellow();
  fireEmbers();
  controls();
  timer();

}

// MENU
// Creates the blue bar on the left side of the sketch

void menu() {

  fill(80, 177, 227);
  rect(0, -20, 20, 450, 5);
}

// GRASS
// Creates the dark blue - green background behind the fire

void grass() {

  fill(15, 20, 20);
  rect(0, 250, 800, 150, 5);
}

// WOODEMBERS
// A nested loop which draws the bright red pixelated effect seen when the fire is off

void woodEmbers() {

  for (float i = 100; i <= 700; i=i+pixelSpacingBig) {
    for (float j = 310; j <= 320; j=j+pixelSpacingBig) {
      fill(random(245, 255), random(25, 45), 0);
      rect(i, j, pixelSpacingBig, pixelSpacingBig);
    }
  }
}

// WOODBRIGHT
// A nested loop which draws the lighter tone of brown of the logs

void woodBright() {

  for (float i = 50; i <= 750; i=i+pixelSpacingBig) {
    for (float j = 280; j <= 360; j=j+pixelSpacingBig) {
      fill(random(100, 108), random(40, 48), 0);
      rect(i, j, pixelSpacingBig, pixelSpacingBig);
    }
  }
}

// WOODDARK
// A nested loop which draws the darker tone of the brown of the logs

void woodDark() {

  for (float i = 30; i <= 780; i=i+pixelSpacingBig) {
    for (float j = 270; j <= 400; j=j+pixelSpacingBig) {
      fill(random(60, 68), random(20, 28), 0);
      rect(i, j, pixelSpacingBig, pixelSpacingBig);
    }
  }
}

// WOODDARKBOTTOMBORDER
// Another nested loop which draws the bottom bottom portion of the logs

void woodDarkBottomBorder() {

  for (float i = 30; i <= 780; i=i+pixelSpacingBig) {
    for (float j = 380; j <= 400; j=j+pixelSpacingBig) {
      fill(random(40, 48), random(10, 18), 0);
      rect(i, j, pixelSpacingBig, pixelSpacingBig);
    }
  }
}

// TIMER
// A conditional statement which displays text based on whether the coresponding time condition is met

void timer() {

   if (millis() >= 5000 && millis() <= 10000) {


    fill(0, 150);
    textSize(32);
    text("The smoke rises high ...", 125, 150);
  } else if (millis() >= 11000 && millis() <= 16000) {

    fill(0, 150);
    textSize(32);
    text("... The flame reaches out to warm ...", 125, 150 );
  } else if (millis() >= 17000) {

    fill(0, 150);
    textSize(32);
    text("... Echoes in the night", 125, 150);
  }
}



// CONTROLS
// Displays the control menu if the mouse X & Y coordinates on within the parameters of the initial rectangle
// If they are, the menu expands and displays the controls text

void controls() {

  fill(255);
  rect(15, 0, 10, 50, 5);

  if ((mouseX <= 25 && mouseX >= 10) && (mouseY <= 70 && mouseY >= 20)) {
    fill(255, 104);
    rect(25, 0, 300, 50, 5);

    fill(0);
    textSize(12);
    text(" A = Ignite", 28, 13);
    text(" S = Rain", 28, 23);
    text(" W = Whoa", 28, 33);
    text(" E = Un - Whoa", 28, 43);
  }
}

// FIREYELLOW, FIREBRIGHTORANGE, FIREMEDIUMORANGE & FIREEMBERS
// Displays the top rectangle of fire
// Conditional is used to control whether fire is displayed or not depending on whether or not a specific button is pressed
// If A is pressed, fire turns on and displays the fire and if S is pressed, the fire is turned off. Fire off is the default.
// This logic applies to FIREBRIGHTORANGE, FIREMEDIUMORANGE & FIREEMBERS as well.


void fireYellow() {


  if (key == 'S' || key == 's') {
    s = !s;
  } else if (key == 'A' || key == 'a') {
    a = !a;

    for (float i = 110; i <= 700; i = i+pixelSpacingBig) {
      for (float j = 60; j <= 270; j = j+pixelSpacingBig) {
        fill(random(245, 255), random(175, 200), 0, 255);
        rect(i, j, pixelSpacingBig, pixelSpacingBig);
      }
    }
  }
}



void fireBrightOrange() {



  if (key == 'S' || key == 's') {
    s = !s;
  } else if (key == 'A' || key == 'a') {
    a = !a;
    for (float i = 90; i <= 720; i = i+pixelSpacingBig) {
      for (float j = 130; j <= 320; j = j+pixelSpacingBig) {
        fill(random(245, 255), random(125, 175), 0, 190);
        rect(i, j, pixelSpacingBig, pixelSpacingBig);
      }
    }
  }
}


void fireMediumOrange() {
  if (key == 'S' || key == 's') {
    s = !s;
  } else if (key == 'A' || key == 'a') {
    a = !a;
    for (float i = 70; i <= 740; i = (i + pixelSpacingBig)) {
      for (float j = 200; j <= 320; j = j + pixelSpacingBig) {
        fill(random(245, 255), random(100, 130), 0, 210);
        rect(i, j, pixelSpacingBig, pixelSpacingBig);
      }
    }
  }
}

// FIREEMBERS
// Using loops and conditionals similar to others with a couple differences.
// The embers travel in a negative (upwards direction) when A is pressed and reset to height of window when they reach 0.
// They also follow pMouse function to allow for some minor pseudo parallaxing.

void fireEmbers() {

  if (key == 'S' || key == 's') {
    s = !s;
  } else if (key == 'A' || key == 'a') {
    a = !a;
    for (float i = 170; i <= 680; i = i + 150) {

      if (emberY >= -30) { 
        fill(255, 54, 16, 200);
        rect(i+pmouseX/4, emberY+pmouseY/4, pixelSpacingBig, pixelSpacingBig);

        emberY = emberY-(emberSlow+speed);
      } else if (emberY <= 100) { 
        fill(255, 54, 16, 200);
        rect(i+pmouseX/4, emberY+pmouseY, pixelSpacingBig, pixelSpacingBig);
        emberY = height;

        emberY = emberY-(emberSlow+speed);
      }
    }
  }
}

// ADDSTROKE
// When W is pressed, stroke effect is added to the drawing, when E is pressed, it is removed. 

void addStroke() {

  if (key == 'w' || key == 'W') { 
    s = !s;
    stroke(0);
  } else if (key == 'e' || key == 'E') {
    noStroke();
    a = !a;
  }
}