boolean key1Pressed = false;

void draw()
{

  background(80);

  pushMatrix();
  pushStyle();
  
  // pushmatrix: http://processing.org/reference/pushMatrix_.html
  // Pushes the current transformation matrix onto the matrix stack.


  // print list of days in the x-axis
  pushMatrix();
  translate(100, (cfg.BarSize.y+cfg.BarSpace.y)*(gFilenames.length)+100); // stretches month number in x-axis, else all the numbers will be displayed in one position
  for (int i = 0; i<36; i++) {
    translate(cfg.BarSize.x+cfg.BarSpace.x, 0); //cfg refers to config class

    //stroke(255);
    textFont(gFont1);
    fill(0,255,0); //def 80
    textAlign(CENTER, CENTER); //def C,C
    //text(str(i+1), 0, 0); // 'text' writes the text
    int month_mod = i % 12; 
    int month_quo = floor(i/12);
    text(months[month_mod]+"'"+str(11+month_quo),0,0);
  }
  popMatrix();

  // print list of manga in y-axis
  pushMatrix();
  translate(105, 50);  // if want to move, modify this!!
  for (int i = 0; i<gFilenames.length; i++) { //dewey is a string array of length 10 defined in GlobalVar
    translate(0, cfg.BarSize.y+cfg.BarSpace.y);

    textFont(gFont1);
    fill(0,255,0);
    textAlign(RIGHT, CENTER);
    text(gFilenames[i], 0, 0);  // do not modify pixel
  }
  popMatrix();

  // print Title and copyright
  textFont(gFont2);
  textAlign(CENTER, CENTER);
  fill(255,255,255); //def 80
  text("Checkouts of Top Manga (2011-2013)", 120, 0, width, 80);

  // print copyright (bottomm right)
  textAlign(LEFT, BOTTOM);
  fill(0,0,255);
  text("Lakshman Nataraj | MAT259 Winter 2014", 0, 0, width-10, height-10);

  // print copyright (bottomm right)
  textFont(gFont1);
  textAlign(RIGHT, BOTTOM);
  fill(255,255,255);
  text("Press '1' to toggle between normalizations", 0, 0, width-10, height-10);

  // draw each bar of musician
  pushMatrix();
  translate(cfg.BarPos.x, cfg.BarPos.y);
  translate(0, -(cfg.BarSize.y+cfg.BarSpace.y)); // top left 
  for ( int i=0; i<gDataMatrices.length; i++ ) {

    translate(0, cfg.BarSize.y+cfg.BarSpace.y); // moving along horizontal (y-axis)

    for (int j=0; j<gDataMatrices[i].length; j++) {  // year
    
      pushMatrix();
      translate(-(cfg.BarSize.x+cfg.BarSpace.x), 0);
      
      for (int k=0; k<gDataMatrices[i][j].length; k++) {  // month
      
        translate(cfg.BarSize.x+cfg.BarSpace.x, 0);

        pushStyle(); // 

        // normalize
        //int nColor = (int)((float)gDataMatrices[i][j][k]/(float)max(gDataMatrices[i][j])*255.0f);  // mode 1
        //// no nomalization
        int nColor = (int)((float)gDataMatrices[i][j][k]/(float)gMaxValue*255.0f);  // mode 1
        
        if(key1Pressed )  {
          nColor = (int)((float)gDataMatrices[i][j][k]/(float)max(gDataMatrices[i][j])*255.0f);
        }
        
        
        float mColor = map(nColor, 0, 255, 255, 0); // 
        int nHue = (int)(240.0f - (float)gDataMatrices[i][j][k]/(float)gMaxValue*240.0f);  // mode2
        float nColor2 = map(nColor, 0, 255, 50, 255); // mode3
        float nColor3 = map(nColor, 0, 255, 10, 255); // mode3
        int nAlpha = 255;

        colorMode(RGB, 255, 255, 255, 255);
        noStroke();
        fill(nColor3,0, 0, nAlpha);
        
        //strokeWeight(0.2);
        //stroke(150);
        //fill(mColor, mColor, mColor); // fill the bar with mcolor
        rect(0, 0, cfg.BarSize.x, cfg.BarSize.y); // draw a rect with the above fill

        popStyle();
      }  // for k
      
      popMatrix();

    }  // for j

  }  // for i
  popMatrix();

  popStyle();
  popMatrix();
}

