Interactive explorable · Ant-inspired collective behavior

SwarmRules.

How can a swarm organize without a leader? These simplified ant-inspired agents move, deposit fading chemical trails, and steer using only nearby signals. Change their local rules and watch collective patterns emerge—without a leader or map.

01 / Trail formation

128 independent agents · one shared trail field
Paused
Your browser needs HTML5 Canvas to view the simulation. Periodic world · opposite edges connect
Turn0
Agents128
Try this → Can you make a stable trail or a branching network? Try changing turning noise and evaporation.
How does the model work?

Can global structure emerge from purely local interactions? This model deliberately gives every ant-inspired agent only a heading, a position, two local pheromone readings, and random angular noise. There is no leader, global map, planning, or direct interaction between agents.

1. Agents and environment

We simulate N = 128 point-like agents in a continuous two-dimensional world of size 96 × 72 (simulation length units). Agent i has a position ri = (xi, yi) and a direction θi. Agents move at the fixed speed v = 0.5 length units per turn. They can overlap: there are no collisions, exclusion forces, or physical obstacles in this first experiment.

The boundaries are periodic: moving beyond the right edge re-enters at the left, and similarly for top and bottom. The pheromone field and sensing also wrap periodically. Initial positions and headings are random; the seed determines the random sequence.

2. A shared pheromone field

The environment stores one nonnegative scalar concentration φ on a 96 × 72 grid, with 0 ≤ φ ≤ 1. All agents read and modify this same field. There is no diffusion: the pheromone spreads only because moving agents deposit it in different places.

Each turn, pheromone first loses a fraction δ through evaporation. After moving, each agent adds D = 0.01 to the grid cell it occupies. Deposition is additive but concentrations are capped at 1:

φt+1(c) = min[1, (1 − δ) φt(c) + D · nc],   D = 0.01

Here c is a grid cell and nc is the number of agents that arrive in that cell during the turn. Without new deposition, concentration follows exponential decay, φt+k = (1 − δ)k φt. Thus δ = 0 means no evaporation, while a larger δ makes trails short-lived.

3. Local sensing

Each agent samples φ at two points ahead of its current position, separated symmetrically by ±45° around its heading. Both sensors are at distance ds = 2.5 from the agent:

si,± = ri + ds (cos(θi ± 45°), sin(θi ± 45°)) φ± = φ(si,±),   ds = 2.5

Sensor locations are continuous, although the field is stored on grid cells. Values between cell centers are obtained by bilinear interpolation from the four nearby cells. The agents never measure the entire pheromone field or the positions of other agents.

4. Steering and movement

Agents turn toward whichever of their two sensors detects the stronger signal. The difference is normalized by the total signal plus φ₀; this limits the response and prevents division by zero when no pheromone is present. Independent random angular noise is added at every turn:

Δθi = λ (φ+ − φ−) / (φ+ + φ− + φ₀) + σ ξi

Each ξi is an independent random number from a standard normal distribution (mean 0, variance 1). Once the heading has changed, the agent moves straight by one fixed-length step:

θi(t + 1) = θi(t) + Δθi ri(t + 1) = wrap[ri(t) + v (cos θi(t + 1), sin θi(t + 1))]

In the absence of pheromone differences, only the turning-noise term changes an agent's direction. In the absence of noise, the agent turns deterministically according to its local pheromone readings.

5. Parameters you control

ParameterWhat changing it does
σ · Turning noiseStandard deviation of the random turn per step (radians). Increasing it makes movement less predictable and can disrupt trails.
λ · Trail followingStrength of steering toward the larger local signal. At λ = 0, sensing does not affect motion.
δ · Trail evaporationFraction removed each turn. Lower values preserve environmental memory longer; higher values favor recent activity.
φ₀ · Steering dampingPositive offset in the steering denominator: increasing it suppresses turning, particularly in weak pheromone fields. Lower values strengthen the response.

The population N is also adjustable from 1 to 1,024. Because each ant independently deposits the same amount D, doubling N changes how quickly pheromone can accumulate and how much collective reinforcement occurs. At N = 1 there are no interactions between different agents.

The remaining controls, other-state following (λₒ) and marking distance (L), belong to the later food–nest experiments and are inactive here. The separate simulation speed control only changes how many turns are computed per displayed frame; the physical rules are unchanged. Changing sliders affects subsequent turns immediately; Reset restarts the agents and clears the pheromone field using the current settings, population, and seed. Changing the population slider adds or removes agents without clearing the existing field.

6. Turn order and what you see

  1. Every agent samples the same current field using its two forward sensors.
  2. Agents change heading (trail response + noise) and move one step with periodic wrapping.
  3. The entire field evaporates by the factor (1 − δ).
  4. Agents deposit D in their destination cells, up to the concentration cap of 1.
  5. The display redraws the current field and ant positions.

About the colors: To make small concentrations visible, the display adjusts contrast to the current field (using its 95th percentile) and hides extremely weak traces. This is visualization only: the agents sense the actual concentrations, not the displayed colors. The ant drawings and walking animation likewise have no effect on the physics.

Why patterns emerge: an ant reinforces places it visits; those trails influence the motion of other ants, which may reinforce them further. This feedback competes with noise and evaporation. The resulting networks or traveling trails are collective effects of local interactions—not paths encoded in any agent's memory. These are simplified ant-inspired agents, not a detailed biological model of real ants.

Background and references

This is a simplified, educational, ant-inspired model. The following publications provide biological and active-matter context; the applet does not numerically reproduce their models or findings.

  1. Deneubourg, J.-L., Aron, S., Goss, S. & Pasteels, J. M. (1990). “The self-organizing exploratory pattern of the Argentine ant.” Journal of Insect Behavior 3, 159–168. doi:10.1007/BF01417909.
  2. Czaczkes, T. J., Grüter, C. & Ratnieks, F. L. W. (2015). “Trail pheromones: An integrative view of their role in social insect colony organization.” Annual Review of Entomology 60, 581–599. doi:10.1146/annurev-ento-010814-020627.
  3. Ziepke, A., Maryshev, I., Aranson, I. S. & Frey, E. (2022). “Multi-scale organization in communicating active matter.” Nature Communications 13, 6727. doi:10.1038/s41467-022-34484-2.