← 🧬 Biology & Life

🐜 Ant Colony


Food collected: 0
Ants: 80
FPS:
Nest A
Nest B (multi)
Food
Pheromone "to food"
Pheromone "home"
Click — add food · Right-click — remove

🐜 Ant Colony — Pheromone Trails

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.

🔬 What It Demonstrates

Stigmergy — indirect communication via environment. Ants deposit pheromones that attract others, creating positive feedback loops for efficient foraging.

🎮 How to Use

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.

💡 Did You Know?

Real ant colonies use over 20 different pheromone chemicals. This model simulates the two most important: "food found" and "way home" trails.

About this simulation

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.

🔬 What it shows

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.

🎮 How to use

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.

💡 Did you know?

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.

Frequently asked questions

What is stigmergy and why does it matter here?

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.

How does an ant decide which way to turn?

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.

What does the pheromone decay slider do?

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.

Is this how real ant colonies behave?

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.

What is the connection to ant colony optimisation?

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.