Every project / Techy

🧬 Game of Life

Conway's famous simulation: four simple rules, and patterns that seem alive.

Game of Life running
Language
HTML, CSS & JavaScript
Level
Intermediate
Category
Techy
▶ Try it & remix

What you'll learn

  • 2D arrays
  • Cellular automata
  • Counting neighbors
  • Wrap-around edges
  • Buttons & controls

How it works

  • The grid is a 2D array of 1s (alive) and 0s (empty).
  • Each step counts every cell's 8 neighbors. The edges wrap around, so the board works like a donut.
  • The rules: a live cell with 2 or 3 neighbors survives, an empty cell with exactly 3 comes alive, and everything else dies or stays empty.
  • A whole new grid is built each step, so every cell changes at the same moment.

Knobs to turn

These settings are near the top of the code. Remix it, change one, and watch what happens. The preview updates as you type.

SettingStarts atFileWhat it does
CELL8life.jssize of each cell in pixels (smaller = more cells)

Files

FileLines
index.html27the page: what shows up
life.js99what it does
style.css55how it looks

Challenges

Each one is a bit harder than the last. Teachers: these make good assignment instructions.

  1. Draw a glider (5 cells) and watch it travel across the board.
  2. Show a generation counter and how many cells are alive.
  3. Color cells by how long they've been alive.
  4. Add a button that places a Gosper glider gun.
  5. Change the rules (e.g. born with 3 or 6 neighbors) and see what happens.