Workshop › Conway's Game of Life › Step 4 of 32
The world will change many times a second, and each time the whole picture must be drawn again. We pack the drawing
lines into a function named draw, so one word repaints everything.
```js
function draw() {
ctx.fillStyle = '#0f172a'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = '#1e293b'
ctx.fillRect(0, TOP, COLS * CELL, ROWS * CELL)
ctx.fillStyle = '#4ade80'
ctx.fillRect(3 * CELL, TOP + 2 * CELL, CELL - 1, CELL - 1)
}
draw()
```function draw() { ... } defines the recipe; it does not run yet.{ and } are its body, indented by two spaces.draw() with parentheses runs it. Each run paints the background first, which wipes the old picture.Wrap all the drawing lines in function draw() { ... } (indented by two spaces) and call draw() after it.
Skills: Functions
← One living cell The world in memory →