/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.tLtghOnlQqT/rev.7 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * CellGrid (v3.0) * by GoToLoop (2015/Jul/09) * * forum.Processing.org/two/discussion/11605/100x100-grid-draw-at-2-fps * studio.ProcessingTogether.com/sp/pad/export/ro.9KbaSot4iSjhZ/latest */ const W = 640, H = 480, FPS = 30, COLS = 100, ROWS = 80, WIDE = W/COLS, WIDE_PLUS = WIDE + 1, TALL = H/ROWS, ON = -1, OFF = 0, RESHUFFLE = true, // change it to false to stop auto-reshuffle. cells = new Uint8Array(COLS*ROWS); void setup() { size(W, H, JAVA2D); noSmooth(); noStroke(); rectMode(CORNER); frameRate(FPS); fill(ON); RESHUFFLE || randomCellRefill(); } void draw() { RESHUFFLE && randomCellRefill(); println(frameRate); background(OFF); for (var col = -1, row = 0, cur = 0, tall = 0; row != ROWS; cur = ++row*COLS, tall = TALL*row, col = -1) while (++col != COLS) cells[cur + col] && rect(WIDE*col, tall, WIDE_PLUS, TALL); } void mousePressed() { RESHUFFLE || randomCellRefill(); } function randomCellRefill() { for (var idx = cells.length; idx--; cells[idx] = random(1) < .5); }