Visualizations
133 / 500

133 · Machine learning

Evolving Walkers

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.

  • Genetic algorithms
  • Spring-mass physics
  • Central pattern generators

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

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.
PreviousCongestion ControlTCP flows share one bottleneck as cars on a night on-ramp. Watch the sawtooth emerge. NextPalladian VillasA shape grammar derives Renaissance villa plans and facades, one rule at a time.

Related visualizations

  • Evolution Strategy LandersMachine learning Fifty ghost landers learn soft touchdowns by natural evolution strategies.
  • Metachronal WalkerNature A millipede and a centipede ripple across a sketchbook page on waves of legs.
  • Ghost RacersMachine learning Sixty neural-net cars evolve to race a track, then face one you draw.
  • BiomorphsAlgorithms Dawkins' Blind Watchmaker: breed recursive ink creatures by choosing a child.
  • Wind WalkerPhysics A six-legged beach machine walks on Theo Jansen's eleven-bar linkage.
  • Point-Light WalkerIllusions Thirteen dots on black, and you see a person walking, running, dancing or carrying a box.
  • CPPN GardenMachine learning Breed images grown by tiny neural networks by picking the ones you like.
  • Symbolic RegressionMachine learning Genetic programming breeds formulas until it rediscovers the law behind the data.
  • Fitness LandscapeAlgorithms Five populations climb a rugged fitness landscape, then get stranded when it shifts.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs