Evolving Creatures, Explained
After reading this you can predict how a foraging population's average speed and body size will shift when you change food supply, mutation rate or world harshness, and you can tell real selection from random noise in the rolling plots.
What this simulation shows
You start with a scattering of creatures in a flat world dotted with food. Each creature carries a small genome: a maximum speed, a body size, a sense radius, a colour, a metabolic rate and a reproduction threshold. Nobody scores them. They wander, steer toward the nearest food they can sense, eat to gain energy and spend energy to move. When a creature's energy crosses its reproduction threshold it splits in two, and the offspring inherits a slightly mutated copy of the genome. When energy hits zero, the creature dies.
That is the whole machine. No fitness function is written down. Yet after a few hundred generations the population looks different from where it started. If food is sparse and far apart, fast movers reach it first and leave more offspring, so average speed climbs. If food is dense and cheap, slow thrifty bodies waste less energy and win, so average speed falls. The colours drift too, since colour is a neutral marker dragged along with whatever genome happens to breed.
Here is the hook. Set food to regrow slowly and start 40 creatures. Within 300 generations you can watch mean speed rise from, say, 1.8 to 2.6 units per step while population sags from 40 to 22. Nobody told the creatures to run. Selection did.
When this model is useful, and when it is not
Use it to build intuition for three linked ideas: that heritable variation plus differential reproduction plus finite resources produces directional change, that the winning trait depends on the environment rather than on any fixed goal, and that evolution is a statistical outcome across a population rather than a change inside one individual.
It is a toy. Real genomes are not six numbers, real metabolism is not one multiplier, and real food does not appear on a grid. The model has no sex, no recombination between two parents, no predators, no aging. Do not read a specific number off this simulation and apply it to a wild species. Read the direction of change and the trade-off structure, which are genuine.
The simulation is stochastic. Two runs with identical settings will not match step for step, and a small population can drift by chance without any selective pressure. Before you claim a trait "evolved", run the same settings three or four times and check the trend holds.
The energy budget that drives everything
The single equation that decides a creature's fate is its energy balance over one step. Everything else is bookkeeping.
Here \Delta E is the energy change this step. g is the energy gained per food item and n_{\text{eaten}} is how many the creature ate. The loss term is the metabolic cost of moving: k is a global constant, m is the metabolism gene, s is body size and v is the speed used this step. The cost rises with the square of both size and speed, which is why big fast bodies are expensive.
The square is the whole story of the trade-off. Doubling speed lets a creature cover twice the distance to food, a linear benefit, but it costs four times the energy, a quadratic penalty. So there is an optimal speed for each food environment, and selection walks the population toward it. When food is abundant the benefit side stays large across many steps, so faster pays. When food is scarce the creature spends most steps finding nothing, so the quadratic cost dominates and thrift wins.
Reproduction is a threshold rule. Let E be current energy and \theta the reproduction threshold gene. When E \ge \theta, the creature splits: energy halves, and the child's genes are the parent's each nudged by a random amount with standard deviation set by the mutation rate.
A worked generation using the demo defaults
Following one creature for five steps
Take the demo defaults: food regrow rate moderate, mutation rate 0.05, starting population 40, world harshness moderate. Give one creature size s = 1.2, speed v = 2.0, metabolism m = 1.0, and use cost constant k = 0.05 and food value g = 12. It starts with energy 15 and threshold \theta = 30.
- Per-step move cost is k \cdot m \cdot s^2 \cdot v^2 = 0.05 \times 1.0 \times 1.44 \times 4.0 = 0.288. Round to
0.29per step. - Step 1: no food reached. Energy 15 - 0.29 = 14.71.
- Step 2: eats one food. Energy 14.71 + 12 - 0.29 = 26.42.
- Step 3: no food. Energy 26.42 - 0.29 = 26.13.
- Step 4: eats one food. Energy 26.13 + 12 - 0.29 = 37.84. This crosses \theta = 30.
- Reproduce: energy halves to 18.92, and a child appears with speed drawn near
2.0, for example2.07after a mutation of about +0.07.
Now compare a thriftier neighbour with v = 1.4. Its move cost is 0.05 \times 1.0 \times 1.44 \times 1.96 = 0.141 per step, less than half. But at 1.4 speed it reaches food later, so over many steps its n_{\text{eaten}} is lower. Whether it out-reproduces the faster creature depends entirely on how spread out the food is. That contest, repeated across 40 creatures for hundreds of generations, is the selection you watch on the plots.
See the trade-off directly
The chart below plots net energy per step against speed for the demo cost values, assuming the creature eats on a fixed fraction of steps that itself grows with speed (faster creatures find food more often) but saturates. The peak is the speed selection favours.
Reading the rolling plots
The tool draws three time series: population count, average speed and average size, plotted against generation. Read them together.
A rising mean speed with a falling population usually means the world got harsher relative to the bodies in it: creatures are dying faster than they breed, and among the survivors the faster foragers dominate. A rising mean speed with a stable population means selection is refining the body plan without threatening the group. A flat mean with a jittery line means you are watching drift, not selection: the trait is neutral or nearly so, and the wobble is sampling noise from a small population.
| Population trend | Mean speed trend | Likely cause |
|---|---|---|
| Falling | Rising | Harsh or sparse food selecting for fast foragers |
| Rising | Falling | Abundant food rewarding thrifty, slow bodies |
| Stable | Flat with jitter | Drift near an optimum, not directed selection |
| Crashing to zero | Any | World too harsh: extinction before adaptation |
Watch the magnitude. A mean speed moving from 2.0 to 2.05 over 50 generations in a population of 40 is inside the noise. A move from 2.0 to 2.6 over 300 generations that repeats across runs is a real trend.
Common mistakes when interpreting a run
The first mistake is reading a single run as truth. With 40 creatures and mutation of 0.05, chance alone can shift a mean by a few percent per hundred generations. Always repeat.
The second is confusing extinction with a failed model. If you crank world harshness high and the population crashes to zero in 20 generations, that is a valid outcome: sometimes adaptation cannot outrun the environment. Lower the harshness or raise the starting population and try again.
The third is expecting an individual to change. No creature evolves. Each one is born with a fixed genome and dies with it. The population average shifts because differently-built creatures leave different numbers of offspring. If you follow one creature you will see nothing evolve, which is exactly the point of the third footnote on the tool page.
To separate selection from drift quickly, set the mutation rate near zero and run. With no new variation, any remaining wobble in the mean is pure sampling noise from a finite population. Then restore mutation and watch a directed trend appear on top of that baseline noise.
Related simulations on this site
If the jittery flat trends here interest you, the Genetic Drift Simulator isolates chance from selection using the Wright-Fisher model, showing how variants fix or vanish in small populations with no fitness difference at all. For self-organising collective behaviour rather than heredity, the Boids Flocking Simulator and the Ant Colony Pheromone Trails both build group patterns from simple local rules. The Slime Mould Networks and Mycelium Growth tools show agents solving transport problems without a central plan. For growth from a tiny rule set, try L-System Plants, and for continuous artificial life see Lenia Continuous Life. The Firefly Synchronization and Neuron Action Potential tools cover coupled oscillators and excitable dynamics if you want the physics side of biology.
Frequently asked questions
Why does average speed sometimes go down instead of up?
Because the favoured speed depends on the food environment. When food is dense and cheap to reach, the quadratic move cost dominates and slow thrifty bodies leave more offspring, so the mean falls. Speed is not "better" in any absolute sense.
Is there a fitness function I can edit?
No, and that is deliberate. Fitness here is emergent: whoever gathers energy fastest crosses the reproduction threshold sooner and leaves more offspring. The trait mix that does this is not written anywhere in the code.
Why do the colours change if colour does nothing?
Colour is a neutral marker. It rides along with whichever genome happens to reproduce. Its drift is a live demonstration of hitchhiking and genetic drift, the same effect the Wright-Fisher model isolates.
My population went extinct. Did I break it?
No. Extinction is a legitimate outcome when the world is harsher than the starting bodies can handle. Reduce harshness, raise the food regrow rate, or start more creatures so variation has time to act before the population runs out.
How many generations before a trend is trustworthy?
For a population near 40 with mutation 0.05, look for a consistent move of more than about 15 to 20 percent in the mean over at least 200 generations, and confirm it repeats across three or four runs. Smaller moves are usually noise.