Workshop › Conway's Game of Life › Step 26 of 32
While the pointer is down, every move writes painting into the cell under it. Letting go sets painting back to
null.
```js
canvas.addEventListener('pointermove', (event) => {
if (painting === null) return
const cell = cellAt(toCanvas(event))
if (cell) grid[cell.r][cell.c] = painting
})
document.addEventListener('pointerup', () => {
painting = null
})
```pointermove: if nothing is being painted, stop; otherwise write painting into the cell under the pointer.pointerup is heard on the whole document, not the canvas: if you let go outside the canvas, the canvas would
never hear it and painting would go on.Write the two listeners under the pointerdown listener, above function update() {.
Skills: Keyboard and mouse input
← Paint or erase? Patterns from text →