> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.Qz-LUvmS5Ci/rev.3
 * 
 * authors: 
 *   GoToLoop

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



/**
 * Graph Bars (v1.0)
 * GoToLoop (2015-Sep-13)
 * 
 * forum.Processing.org/two/discussion/12490/
 * is-it-possible-to-create-an-indexed-list-array-of-rgb-values-for-fill
 *
 * studio.ProcessingTogether.com/sp/pad/export/ro.9qxrHCEYG6Z9o
 */

import processing.serial.Serial;

static final int QTY = 10, DIM = 60, FPS = 10;
final color[] colors = new color[QTY];
final int[] heights  = new int[QTY];
int idx;

void setup() {
  size(600, 200, JAVA2D);
  smooth(4);
  noLoop();
  frameRate(FPS);

  strokeWeight(1.5);
  stroke(0);
  rectMode(CORNER);

  keyPressed(); // Comment it out once you've got your PALETTE[].
  //new Serial(this, "COM6", 19200); // Uncomment to activate it!
}

void draw() {
  background(0300);
  for (int i = 0; i != QTY; ++i) {
    fill(colors[i]);
    rect(i*DIM, height, DIM, -heights[i]);
  }
}

void serialEvent(Serial s) {
  heights[idx] = s.read();
  if ((idx = (idx + 1) % QTY) == 0)  redraw();
}

void keyPressed() {
  for (int i = 0; i != QTY; ++i) {
    colors[i]  = (color) random(#000000) | #000000;
    heights[i] = (int) random(height);
  }
  redraw();
}

void mousePressed() {
  keyPressed();
}