Each sphere is an organism carrying one heritable trait: a body-colour hue in [0,1] that determines how well it is camouflaged against the habitat floor colour. Every generation, the population's fitness is scored, the least-fit fraction is culled by predation, and survivors reproduce with a chance of mutation — the three core ingredients of natural selection: heritable variation, differential survival, and descent with modification.
fitness_i = 1 - circularDist(hue_i, hue_env)
cull bottom (selectionPressure × N) by fitness
offspring_hue = parent_hue + N(0, mutationRate) (survivors only)
next generation size restored to N via resampling
- Mutation rate — standard deviation of the random hue change passed to offspring each generation.
- Selection pressure — fraction of the population removed by predation each generation, ranked by fitness.
- Generation speed — how often a new generation is computed.
- Shift habitat — randomises the habitat's camouflage colour, simulating environmental change and testing whether the population can re-adapt.
This mirrors real cases like peppered-moth melanism, where pollution-darkened tree bark shifted which wing colour survived predation, driving the population's average trait toward the new optimum over generations.