Workshop › Conway's Game of Life › Step 6 of 32
draw should show the data: visit every cell of grid with two nested loops and paint a green square where the cell
is 1.
```js
ctx.fillStyle = '#4ade80'
for (let r = 0; r < ROWS; r++) {
for (let c = 0; c < COLS; c++) {
if (grid[r][c]) ctx.fillRect(c * CELL, TOP + r * CELL, CELL - 1, CELL - 1)
}
}
```for (let r = 0; r < ROWS; r++) runs its body with r = 0, 1, 2 ... 47: every row.c for every column of that row.if (grid[r][c]) is true for 1 and false for 0, so only live cells are painted, at column c and row r.In draw, replace the line that paints the fixed square with the two loops. The fillStyle line above stays.
Skills: Loops
← The world in memory A random soup →