Workshop › Conway's Game of Life › Step 1 of 32
Four simple rules, and a world that comes alive. A grid of cells, counting neighbours, why every cell must change at the same moment (double buffering), a world that wraps around, painting with the pointer, and the famous glider gun.
The Game of Life (John Conway, 1970) is a "zero-player game": you set up a pattern of cells and four simple rules decide everything after that. First we need a board: find the canvas, take its pen and paint it dark.
```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')
ctx.fillStyle = '#0f172a'
ctx.fillRect(0, 0, canvas.width, canvas.height)
```document.getElementById('game') finds the canvas; const canvas = names it.canvas.getContext('2d') gives the pen with all drawing commands; we call it ctx.fillStyle picks a color, fillRect(x, y, width, height) fills a rectangle. (0, 0) is the top-left corner, and
canvas.width, canvas.height (480, 480) make it cover everything.Write the lines under the three comment lines, then press Run.
Skills: Drawing on a canvas