Creatures learn to walk by evolution, one generation at a time.
Each walker is a body of masses, springs and muscles that contract on a rhythm set by its genes, with grippy or slippery feet. A whole population is simulated at once on rolling hills and scored by how far it gets. The best survive, cross over and mutate into the next generation, sometimes gaining or losing a foot or a muscle, so stumbling blobs turn into shuffles, hops and gallops. The camera follows the crowned leader, with ghosts of the others behind it.
Try it. Click to start evolution over. Press F to fast-forward.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build an evolution simulator with JavaScript and the HTML canvas element, where little spring-and-mass creatures learn to walk through a genetic algorithm. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Draw a sky and flat ground.
- A creature's genome is 3 to 5 nodes (a starting position and a friction value each) plus a list of muscles connecting pairs of nodes. Each muscle has an amplitude and a phase, and the creature has one frequency.
- Simulate with a fixed time step: each muscle is a spring whose rest length is its starting length times (1 + amplitude * sin(2 * PI * frequency * t + phase)). Add gravity and damping. When a node hits the ground, stop it going down and cancel some of its sideways speed according to its friction.
- Run 30 creatures side by side for 10 seconds, all starting at x = 0. Fitness is how far the center of mass moved right.
- Then keep the best quarter, fill the rest with mutated copies of the better half (nudge positions, friction, amplitudes and phases), and start the next generation.
Once that works, make it beautiful:
- Draw the leader solid and everyone else as translucent ghosts, and make the camera follow the leader. Add distance markers on the ground.
- Give the creatures personality: a soft colored skin around their nodes, dark grippy feet and pale slippery ones, and a pair of googly eyes.
- Show the generation number and a small chart of the best and median distance per generation, and let F fast-forward.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as hilly terrain, mutations that add or remove nodes, or a tiny neural network that controls the muscles from touch sensors.