Ant Observation
Place food, draw walls, and watch ants form foraging trails.
- Elapsed time
- Food remaining
- 0items
- Ants carrying food
- 0ants
- Food delivered
- 0items
How it works and legend
Choose a tool and brush size, then tap or drag in the box. Walls avoid the nest and food.
Blue marks food pheromones; orange marks home pheromones. Searching ants follow blue and leave orange, while ants carrying food follow orange and leave blue. Searching ants also respond to nearby food odors. Pheromones fade over time.
The world has 240×160 cells and 300 ants, updated every 1/30 of a model second. Ant positions and headings are continuous; food, walls and pheromone concentrations are stored per cell. Both pheromone fields start at zero.
Movement and foraging
- Each update first checks for pickup and delivery at the current position. A searching ant on a food cell takes one item, turns 180 degrees and starts carrying it. Inside the nest radius of 5 cells, it delivers the item, turns 180 degrees again and resumes searching.
- Searching ants read blue food pheromones; carrying ants read orange home pheromones. Three sensors look straight ahead and 0.7rad (about 40 degrees) to either side, at an individual distance of 3.5–6.5 cells. A wall between the ant and a sensor point makes its reading zero.
- Ants turn smoothly according to the difference between the left and right readings. A strong forward reading favors continuing straight. In the formula below, L, F and R are the left, forward and right concentrations, and Δθ is the heading change in radians per update. This rule applies when the strongest reading exceeds 0.0001.
- Searching ants also sense food odors within a distance of less than 8 cells. Nearby cells with more food contribute more strongly. The combined direction adds a turn of up to 1.2rad per second. Food behind walls or food that has been depleted contributes nothing.
- After adding a random turn, ants move at 5.85–12.15 cells per second. If a wall or the world boundary blocks the movement, they stay in place and turn by a random angle between 90 and 270 degrees. Ants do not collide with each other.
Individual differences use a fixed coefficient q between 0.7 and 1.3, assigned at creation. Sensor distance is 5×q, and the concentration exponent is k=0.9/q. A higher q means a longer sensing distance and a weaker bias toward the strongest trail. Each ant also has independently fluctuating movement speed.
k = 0.9 / q
Δθ = (R^k - L^k) / (L^k + 2F^k + R^k) × (4.5 / 30)
When pheromones are deposited
Searching ants deposit home pheromones; carrying ants deposit food pheromones in their current cell on every update. The amount follows the formula below. For a searching ant, d is the distance actually walked since last being in the nest. For a carrying ant, it is the distance walked since the last pickup. Deposits decrease as the ant travels farther from its source.
Deposit per ant per update = 2.5 × exp(-d / 35)
After all ants move, existing pheromones diffuse into accessible cells above, below, left and right, then undergo evaporation before new deposits are added. The diffusion coefficient is 0.6 and the evaporation rate is 0.12 per second: each update multiplies concentrations by exp(-0.12/30). Without new deposits, the total halves in about 5.8 seconds. Pheromones cannot pass through walls, and each cell is capped at a concentration of 100.
Exploration continues along established trails
The turning fluctuation w changes each update as w=0.9×previous w+0.1×uniform random[-1,1]. Another random value adds a turn of 0.09×(uniform random[-1,1]+2w). This is multiplied by 1.5 when the strongest pheromone reading exceeds 0.001 or food odor is detected, and by 2.4 otherwise. Random turns remain active on trails; there is no fixed percentage of dedicated scouts.
Ants do not directly know the direction of the nest or food. They use nearby information, and ants exploring another route leave pheromones that can change the trails. Short routes allow quicker round trips and stronger deposits near the source, while unused trails fade. Finding the shortest route is not guaranteed.
Editing, resetting and time
The food brush adds 100 items per covered cell. Walls avoid the nest and food; the eraser removes only walls and food on the ground. Choosing an initial map beside Reset starts that layout paused. Later resets restore the selected map, clearing edits, pheromones, carried food, delivery counts and elapsed time. Speed and tool settings are kept.
Elapsed time is model time. Playback speed changes the number of updates, keeping the rules of each update the same. Time stops while paused or while the tab is hidden. A fixed random seed gives the same result for the same map and the same actions at the same update counts.