Every project / Techy
🧬 Game of Life
Conway's famous simulation: four simple rules, and patterns that seem alive.
- Language
- HTML, CSS & JavaScript
- Level
- Intermediate
- Category
- Techy
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.
| Setting | Starts at | File | What it does |
|---|---|---|---|
CELL | 8 | life.js | size of each cell in pixels (smaller = more cells) |
Files
| File | Lines | |
|---|---|---|
index.html | 27 | the page: what shows up |
life.js | 99 | what it does |
style.css | 55 | how it looks |
Challenges
Each one is a bit harder than the last. Teachers: these make good assignment instructions.
- Draw a glider (5 cells) and watch it travel across the board.
- Show a generation counter and how many cells are alive.
- Color cells by how long they've been alive.
- Add a button that places a Gosper glider gun.
- Change the rules (e.g. born with 3 or 6 neighbors) and see what happens.