Camouflage Evolution in Bugs

A tool for understanding the process of natural selection

(works best on desktop)
full simulation description here

What is this game?

This interactive simulation lets you experience evolution of camouflage in real time. Acting as a bug-eating predator, your actions become the selection pressure that drives the evolution of the bug population.

How to play

You are a predator hunting bugs. Eat them by hovering your mouse over them (or tapping if on mobile). Your hunger timer counts down constantly, and you’ll need to keep eating to survive. If you do die, you can keep playing, but the objective should be to go as long as you can without dying. In about 1-3 minutes of playing, you'll see the bug population evolve a camouflage strategy. It's a classic survival of the fittest situation - the bugs that are harder to see against the background image will tend to survive and procreate.

How does the simulation work?

  • This species of bug, let's call it scarabidus chromatis has a single gene that controls its color.
  • The bug population begins with each bug having a randomly chosen color. That is to say, each bug has a different allele of the color gene.
  • The population stays constant—when you eat a bug, it’s immediately replaced.
  • The replacement is a child of a randomly selected surviving bug.
  • The child inherits the parent’s color gene, but with a small mutation in its red, green, and blue (RGB) values.
  • The only trait that evolves is color, which affects how visible bugs are against the background.
  • Bugs that blend in are less likely to be eaten, so their genes (colors) are more likely to persist.
  • Over time, the population evolves to match the background—an adaptive response to selection pressure.

This is too easy!

If the default settings are too easy, it can feel like you're pretending to go after the easiest-to-see bugs just to 'make the simulation work'. Doing so is a good demonstration of artificial selection, but it's not what we're after. Luckily, there's a way to get genuine natural selection - just alter the settings! If the defaults feel too easy, make the game harder by decreasing the hunger timer or making the bugs smaller. You should adjust the settings so that the optimal hunting strategy is to go after the most conspicuous bugs. If you do this, you'll see genuine natural selection. Similarly, if you're living a care free life pursuing a 'combing' strategy (i.e. just dragging the cursor around until you get a bug, without really looking) you should be able to alter the settings so that this is not the most effective strategy.

Simulation controls

  • Population Size: Total number of bugs present at any time.
  • Phenotypic Distance: Controls how much the color gene can change with each reproduction. For example, if the parent bug's color gene is RGB(50,50,50) and the phenotypic distance is set to 7, the offspring bug will be either RGB(59,59,59) or RGB(43,43,43)
  • Custom Initial Bugs: Instead of randomly chosen colors, you can set whatever colors you want in the initial population
  • Background: Changes the environment to test camouflage under different conditions.
  • Grow Speed: If the bugs just pop into existence fully formed it tends to catch the eye, making them easier to spot. This could potentially skew the simulation by giving you, the predator, a hunting strategy that does not depend on color. Having the bugs grow slowly diminishes this effect.
  • Max Offspring Radius:This is the maximum distance that an offspring bug will spawn from its parent.
  • World Wrap:If the offspring distance is out of bounds, it will wrap around, like in Pac Man. If world wrap is off, bugs will tend to cluster around the edges.
  • Flash on Death: When you die of starvation the screen flashes red. Turn it off if this is annoying to you.
  • Random Step: You can let the simulation run for a given number of steps. Instead of you choosing which bugs are eaten, a random bug is chosen each step. See the section below about genetic drift

Why does it matter?

Natural selection is powerful not because it is guided by an intelligent designer, but because it isn’t. This simulation helps reveal how adaptive traits can emerge from simple rules. There is no master plan, no top-down design—just blind variation and differential survival. What looks like purposeful camouflage is actually the result of numerous mindless steps. The bugs aren’t trying to evolve; they’re the subject of an algorithm. This bottom-up process is the essence of evolution by natural selection and the key to understanding the beauty of the biological world.

A note on genetic drift

Genetic drift is the random fluctuation of allele frequencies in a population. In other words, it is evolution in the absence of selection pressures. It's somewhat counterintuitive. For example, if you start out with, say, 50 different alleles in a population, and leave it to a random process to choose which ones get to replicate, you end up with a severe reduction in the overall number of alleles in the population. Those alleles 'drifted' to a higher frequency purely by chance. This game's 'random step' feature lets you simulate genetic drift. Reset the game and select a random step of 500. You will see that the diversity of the initial population is not sustained. A few lucky alleles will have drifted to higher frequencies. In the real world, multiple evolutionary forces act simultaneously on a population. Disentangling their relative influence is a central challenge for evolutionary biologists.

How to read population snapshots

How to read population snapshots
  • Population snapshots tell the story of the evolving bug population.
  • Each vertical band is a snapshot of the actual population.
  • When a bug is eaten and another procreates, the allele frequencies change.
  • Switch from 'grid' view to 'line' view to trace the survival of individual bugs throughout the simulation.

A Brief History of the Simulation

I didn't come up with this simulation. There have been at least 3 previous iterations:

  1. 1986: Bishop & Anderson create a classroom activity using colored beads.
  2. 1990s: Steve Brewer develops a computer version at UMass. I once saw this webpage years ago, but it's since been taken down.
  3. 2005: Wilensky and Novak implement a NetLogo version.
Wilensky NetLogo implementation

This is Wilensky and Novaks' version. My version introduces several new features:

  1. Population Snapshots: Visualize allele frequencies changing over time.
  2. Hunger Timer: Makes contrast hunting the optimal strategy
  3. Dominant Colors: Compare bug colors with the background in real time.
  4. Random Step: Simulate genetic drift.
  5. Custom Initial Bugs: Set the starting alleles manually.

Photo Credits

  • sand: "Sand from Gobi Desert" by Siim Sepp – Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons.
  • candy: Marco Guidi/EyeEm/Getty Images
  • carpet: Home Depot
  • gravel: Pet Solutions
  • leaves: Minerva Studio/Shutterstock
  • everything else: generated with chatGPT