openobject.org

RandomBlink in Processing

From Physical Programming

/*Just playing around with grid-base programing. By somehow, when I save this into an application, the result .exe doesn't work like the one I run in Processing.*/

 int cellWidth = 50;
 int cellHeight = 40;
 int count, tempx, tempy;
 
 void setup() {
   size (800, 600);
   background (255, 150, 150);
   smooth();
   stroke(255);
   frameRate (3);
   
   int i;
   for (i=1; i<16; i++)
   line (width/16*i, 0, width/16*i, 600);
   
   for (i=1; i<15; i++)
   line (0, height/15*i, 800, height/15*i);
 }
 
 void draw(){
   count++;
   int x = int(random(16)), y = int(random(15));
   if(count%2==1)
   drawCell(x, y);
 else
   clearCell(tempx, tempy);
   tempx=x;
   tempy=y;
 }
 
 void drawCell(int x, int y)
 {
  rectMode(CORNER);
  int originx = x * cellWidth;
  int originy = y * cellHeight;
  fill(100);
  rect(originx, originy, cellWidth, cellHeight);
 }
 
 void clearCell(int x, int y)
 {
  rectMode(CORNER);
  int originx = x * cellWidth;
  int originy = y * cellHeight;
  fill(255, 150, 150);
  rect(originx, originy, cellWidth, cellHeight);
 }