Conway’s Game of Life: a zero-player cellular automaton where each cell lives, dies, or is born each tick based on its eight neighbors. Grid wraps at the edges (toroidal), so gliders and other spaceships loop forever instead of running off the board. Starts from a random soup; click any cell to toggle it by hand.
Reuse
src/life.js exports pure functions over a plain 2D array of 0/1
(grid[y][x]): createGrid(cols, rows), randomize(cols, rows, density),
step(grid) returning the next generation, and stampGlider(grid, x, y) for
seeding a known-good pattern. No dependencies, no rendering — bring your own
renderer.
Gotchas
stepalways allocates a fresh grid rather than mutating in place, so in-progress neighbor counts never read half-updated cells.- The demo bundles its own copy of
life.js(self-contained by contract); re-copy after editingsrc/. - Controls: click/tap toggles a cell, space play/pauses, R reseeds a random soup, C clears the board, G stamps a glider near the top-left corner.