Watch ants find food using pheromone communication — an emergent self-organised behaviour where simple rules create complex colony intelligence. Each ant follows local chemical gradients, yet the colony as a whole finds optimal paths.
Stigmergy — indirect communication via environment. Ants deposit pheromones that attract others, creating positive feedback loops for efficient foraging.
Use sliders to change ant count, food sources and pheromone decay rate. Click on the field to add food. Right-click to remove it. Toggle two-colony mode to watch competition.
Real ant colonies use over 20 different pheromone chemicals. This model simulates the two most important: "food found" and "way home" trails.
This is an agent-based model of ant foraging driven entirely by local rules. Each ant wanders, senses pheromone concentrations in three directions ahead, and steers toward the strongest signal while depositing its own trail. Two scalar fields are tracked on a grid: a "to food" trail laid by searching ants and a "home" trail laid by returning ones. Decaying trails plus positive feedback let the colony converge on short routes — an example of stigmergy, the principle behind ant colony optimisation.
Emergent path-finding from simple agents. Ants read pheromone in a forward, left and right cone set by the view angle, turn toward the densest cell sampled 12 pixels ahead, and add a small random wander. Trails are stored as two Float32Array grids (4 px cells) that are multiplied by the decay factor every frame, so unused paths fade while reinforced ones persist.
Sliders set ant count (10–300), number of food sources (1–8), pheromone decay (0.9–0.999), ant speed and the sensing view angle (10–120°). Left-click adds a food source; right-click removes a nearby one. Tick "Two colonies" to pit nest A against nest B, each with its own trails. The panel reports food collected, ant count and FPS; Restart respawns everything.
Real ants use over twenty distinct trail and alarm pheromones. This model abstracts just two channels — "food found" and "way home" — yet that minimal pair is enough to reproduce the famous double-bridge experiments in which colonies reliably discover the shorter of two routes.
Stigmergy is indirect coordination through the environment rather than direct messaging. An ant changes the world by leaving a pheromone mark, and that mark influences the next ant that passes. No ant has a map or a plan, yet the accumulated marks let the colony behave as if it does, which is exactly what this simulation visualises.
Each step the ant samples the pheromone grid it is currently following — the food trail when searching, the home trail when carrying food — at three points 12 pixels ahead: straight, left and right, separated by the view angle. It rotates toward whichever sample is strongest, then adds a small random nudge so the swarm keeps exploring rather than freezing on one path.
Decay is a multiplier applied to every grid cell each frame, from 0.9 up to 0.999. Values near 0.999 make trails persist for a long time, so even poor routes linger and the colony adapts slowly. Lower values erase trails quickly, forcing constant re-exploration. The interesting behaviour emerges in between, where good paths are reinforced faster than they fade.
It captures the core mechanism faithfully: deposit, follow, and evaporate. Real ants add factors this model omits, such as trail recruitment intensity, terrain, and many chemical types. The double-trail scheme and exponential decay here mirror the standard textbook model and the ant colony optimisation algorithm, so it is a sound conceptual rather than biologically exact representation.
Ant colony optimisation, or ACO, is a class of algorithms inspired by exactly this foraging behaviour. Virtual ants build candidate solutions, deposit pheromone in proportion to solution quality, and evaporation discounts older choices. Run on a graph instead of an open field, the same deposit-follow-decay loop solves routing problems like the travelling salesman, which is why this sim sits in the algorithms family.