()
| 25 | } |
| 26 | |
| 27 | function draw() { |
| 28 | background(236, 236, 236); |
| 29 | |
| 30 | for (let i = 0; i < column; i++) { |
| 31 | for (let j = 0; j < rows; j++) { |
| 32 | let x = i * resolution; |
| 33 | let y = j * resolution; |
| 34 | if (grid[i][j] == 1) { |
| 35 | fill(247,136,136); |
| 36 | stroke(144,204,244); |
| 37 | rect(x, y, resolution - 1, resolution - 1); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | let next = MAKE2DARRAY(column, rows); |
| 43 | |
| 44 | // Compute next based on grid |
| 45 | for (let i = 0; i < column; i++) { |
| 46 | for (let j = 0; j < rows; j++) { |
| 47 | let state = grid[i][j]; |
| 48 | // Count live neighbors! |
| 49 | let sum = 0; |
| 50 | let neighbors = COUNTNEIGHBORS(grid, i, j); |
| 51 | |
| 52 | if (state == 0 && neighbors == 3) { |
| 53 | next[i][j] = 1; |
| 54 | } else if (state == 1 && (neighbors < 2 || neighbors > 3)) { |
| 55 | next[i][j] = 0; |
| 56 | } else { |
| 57 | next[i][j] = state; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | grid = next; |
| 63 | } |
| 64 | |
| 65 | function COUNTNEIGHBORS(grid, x, y) { |
| 66 | let sum = 0; |
nothing calls this directly
no test coverage detected