> show canvas only <


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

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



/** 
 * isKeyDown() (v3.1)
 * by  Quarks (2013/May)
 * mod GoToLoop (2013/Aug)
 * 
 * Forum.Processing.org/topic/
 * problems-with-multiple-key-presses-more-specific-getkeytext-int-does-not-work
 *
 * Forum.Processing.org/topic/the-function-getkeytext-int-does-not-exist
 *
 * Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G
 */

static final String TABULAR = "\t";
static final color FG = #FF0000, BG = -1;
static final int KEYS = 0500, SMOOTH = 3;
static final float FPS = 60.0, WEIGHT = 1.0;

final boolean[] keysDown = new boolean[KEYS];

void setup() {
  size(01000, 0500);
  smooth(SMOOTH);
  frameRate(FPS);

  colorMode(RGB);
  strokeWeight(WEIGHT);
  stroke(BG);
}

void draw() {
  final int p = frameCount % width;
  line(p, 0, p, height);
  for (int k = 0; k < KEYS; )  if (isKeyDown(k++))  set(p, k, FG);
}

void keyPressed() {
  processKey(keyCode, true);
  print(keyCode + TABULAR);
}

void keyReleased() {
  processKey(keyCode, false);
}

void processKey(final int k, final boolean isDown) {
  if (k < KEYS)  keysDown[k] = isDown;
}

boolean isKeyDown(final int k) {
  return keysDown[k];
}