$ Game of Life

View on GitHub → · Try the demo →

John Conway's Game of Life is a zero-player cellular automaton. A grid of cells that live, die, and reproduce based on four simple rules. Despite its simplicity, it produces an astonishing variety of behavior: still lifes, oscillators, spaceships, and even universal computation.

the four rules

  1. Any live cell with fewer than two live neighbors dies (underpopulation).
  2. Any live cell with two or three live neighbors survives.
  3. Any live cell with more than three live neighbors dies (overpopulation).
  4. Any dead cell with exactly three live neighbors becomes alive (reproduction).

controls

  • tap: toggle a cell
  • drag: draw cells
  • space: pause / play
  • r: random restart
  • c: clear the grid

### preset patterns

The demo includes five classic patterns that showcase the range of behavior possible in Life, from simple motion to infinite growth.

  • Glider

    The simplest spaceship. A 5-cell pattern that moves diagonally one cell every 4 generations. Gliders are the workhorses of Life. They carry information, trigger reactions, and form the basis of complex constructions like the Gosper Glider Gun.

  • LWSS (Lightweight Spaceship)

    A 9-cell spaceship that moves horizontally, leaving a trail of sparks. One of three standard spaceships (LWSS, MWSS, HWSS). Essential building blocks for creating collisions and signal paths in larger constructions.

  • Pulsar

    A period-3 oscillator and the most common naturally occurring oscillator in Life. Its 48 cells cycle through three distinct phases, returning to the starting configuration every 3 generations. Beautiful steady-state motion.

  • R-pentomino

    A 5-cell methuselah and one of the most famous patterns in Life. From just five cells, it runs for 1103 generations before stabilizing, leaving behind a complex landscape of still lifes, oscillators, and escaping gliders. Tiny input, enormous chaos.

  • Gosper Glider Gun

    The first known finite pattern that grows without bound, discovered by Bill Gosper in 1970. A period-30 oscillator that emits a steady stream of gliders. Its existence proved that Life patterns can grow infinitely, settling a fundamental question about the automaton.

### implementation

The simulation runs on a toroidal grid (cells wrap around edges) using flat Uint8Array buffers with double-buffering. Each generation is computed into a fresh buffer, then swapped. This avoids in-place mutation artifacts and keeps the update loop clean.

Rendering uses ImageData for bulk pixel writes rather than individual fillRect calls. The simulation is throttled to ~30fps via requestAnimationFrame with a timestamp gate, keeping CPU usage low while still looking smooth.

Everything is vanilla JavaScript. No framework, no build step, no dependencies. The whole thing runs from a single <script> tag on a canvas.

### tech stack

  • - HTML Canvas: pixel-level rendering via ImageData for high-throughput cell drawing
  • - Vanilla JavaScript: zero dependencies, single file, no build step
  • - Flat Array Buffers: Uint8Array with double-buffering for zero-allocation simulation steps
  • - Toroidal Grid: edge wrapping for seamless pattern behavior
  • - Preset Patterns: glider, LWSS, pulsar, R-pentomino, Gosper Glider Gun with centered placement