aswartzell.net cellular automata

int sx, sy; 
int[][][] world;
int range = 20;
int density = 3;
float noise = 0.75;
int count;

void setup() { 
  size(455, 455);

  colorMode(HSB, 360, 100, 100, 100);

  range = int(random(1, 20));
  density = int(random(1, 20));
  noise = random(0, 1);

  sx = width;
  sy = height;
  world = new int[sx][sy][2]; 

  background(0, 0, 100); 
  count = 0;

  // Set random cells to 'on' 
  world[sx/2][sy/2][0] = 1;
} 

void draw() { 
  // Drawing and update cycle 
  for (int x = 0; x < sx; x=x+1) { 
    for (int y = 0; y < sy; y=y+1) { 
      if ((world[x][y][1] == 1)) { 
        world[x][y][0] = 1; 
        set(x, y, color(0));
      } 
      if (world[x][y][1] == -1) { 
        world[x][y][0] = 0;
      } 
      world[x][y][1] = 0;
    }
  } 
  // Birth and death cycle 
  for (int x = range; x < sx-range; x=x+1) { 
    for (int y = range; y < sy-range; y=y+1) { 
      int count = neighbors(x, y); 
      if (count == 1 && world[x][y][0] == 0 && random(0, 1) > noise) {
        world[x][y][1] = 1;
      } 
      if (count > density && world[x][y][0] == 1) {
        world[x][y][1] = -1;
      }
    }
  }
  count++;
  if (count > width/(range+2)){
    saveFrame("r"+range+"_d"+density+"_n"+noise+"_"+nf(count, 4)+".png");
    setup();
  }
} 

// Count the number of adjacent cells 'on' 
int neighbors(int px, int py) { 
  int count = 0;
  for (int x = px-range; x <= px+range; x++) { 
    for (int y = py-range; y <= py + range; y++) { 
      if (world[x][y][0] == 1)
        count++;
    }
  }
  return count;
} 

void mouseClicked() {
  noLoop();
}

void fade(int rate) {
 
  colorMode(HSB, 360, 100, 100);
  //fade the trails
  loadPixels();
  for (int i=0; i<width*height; i++) {
    color c = pixels[i];
    if (brightness(c) < 100)
      pixels[i] = color(hue(c), saturation(c), brightness(c)+1*rate);
    if (saturation(c) > 0)
      pixels[i] = color(hue(c), saturation(c)-1*rate, brightness(c));
  }
  updatePixels();
}