sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Constants
// Cell initialization

function setup() {
  // Setup boilerplate

  for (let x=2;x<=18;x+=4) {
    for (let y=2;y<=18;y+=4) {
      let color=Math.ceil(Math.random()*2);
      cells[cellIndex(x, y)] = color;
      let neighbors = neighborCells(x, y);
      for (let i=0;i<neighbors.length;i++) {
        cells[neighbors[i]] = color;
      }
    }
  }
  
  renderCells();
}

// northIndex()
// southIndex()
// eastIndex()
// westIndex()
// neighborCells()
// cellIndex()
// renderCells()
Preview