> show canvas only <


/* built with Studio Sketchpad: 
 *   http://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   http://studio.sketchpad.cc/sp/pad/view/ro.b5bOOrnhRR8/rev.10
 * 
 * authors: 
 *   GoToLoop

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   http://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/**
 * GridGUI Sample (v2.01)
 * by GoToLoop (2013/May)
 *
 * forum.processing.org/topic/basic-gui
 * studio.processingtogether.com/sp/pad/export/ro.98-pSvW97Q-RE/latest
 */

static final byte GRID = 8;
boolean[][] leds = new boolean[GRID][GRID];

static final color OFF = 0350, ON  = #0000FF;
static final short DIM = 0100;

void setup() {
  size(GRID*DIM + 1, GRID*DIM + 1, JAVA2D);
  noLoop();
  frameRate(60);

  smooth(4);
  stroke(0);
  strokeWeight(1.5);

  initGrid();
}

void draw() {
  for (int row = 0; row != GRID; ++row)
    for (int col = 0; col != GRID; ++col) {
      fill(leds[row][col] ? ON : OFF);
      rect(col*DIM, row*DIM, DIM, DIM);
    }
}

void keyPressed() {
  initGrid();
  redraw();
}

void mousePressed() {
  keyPressed();
}

void initGrid() {
  for (int row = 0; row != GRID; ++row)
    for (int col = 0; col != GRID; ++col)
      leds[row][col] = random(1) > .5;
}