PINONITE/NIKOLAS PINON ← CREATIVE SYSTEMS
PINONITE · FIELD NOTES · CREATIVE SYSTEMS
PUBLISHEDAugust 10, 2026

PERSONAL PROJECT · BUILT AFTER HOURS

Creative coding CREATIVE SYSTEMS ↗

How pheromone trails make an ant colony simulation come alive

An interactive ant colony simulation where local steering, pheromone trails, evaporation, obstacles, and recovery turn lucky discoveries into shared paths.

I built this because I wanted to watch ants do ant things. There was no product brief and no practical destination. Simulating the natural world is simply fun: a few understandable rules can get close enough to a complicated behavior that something surprising appears on screen.

The finished colony has dozens of ants, two food sources, fading signals, obstacles, and three ways to view the same world. Starting there asks the reader to decode everything at once. So this version begins with one ant and one question: what has to be true before a trail can exist?

A useful path begins as an accident

Start with one ant in an empty field. It needs enough forward motion to travel, enough variation to explore, and enough boundary pressure to stop turning the edge into an infinite treadmill.

LIVE MODEL / ant motion

Movement before memory

INTERACTIVE
WORLD SO FAR
  1. Movement before memory +
QUESTION What keeps random exploration from becoming an endless walk along the wall?
COMPARE TWO CONDITIONS
WATCH FOR

Drag the ant near a wall and release it. Boundary correction should bend its heading before the wall becomes a treadmill.

YOUR TURNCompare condition A with B, then inspect what changed.
DRAG THE ANT TO AN EDGE, THEN RELEASE
TURN VARIANCE 34° BOUNDARY FORCE 0.9×
Accessible experiment transcript

A single ant integrates forward motion, bounded turning, and an inward edge force before pheromones exist. Canvas gesture: drag the ant to an edge, then release.

Drag the ant near an edge and release it. Its wandering continues, but the boundary correction bends only the unsafe part of its heading.

This fixes locomotion, but the result is still obviously broken. The ant can pass beside food without reacting. Even when it collides with food by chance, nothing in its movement policy can use that discovery again.

The first missing piece is not colony intelligence. It is local perception.

A smell can bend one path

Give the ant five samples in a fan: hard left, soft left, forward, soft right, and hard right. Each sample reads the relevant local field, subtracts edge risk, and keeps a small forward preference. The best valid sample becomes a steering target.

LIVE MODEL / ant sensing

Five samples, one steering target

INTERACTIVE
WORLD SO FAR
  1. Movement before memory ✓
  2. Five local samples +
QUESTION How can an ant choose a direction without knowing where the food is?
COMPARE TWO CONDITIONS
WATCH FOR

Drag the signal around the ant. The strongest sample should change immediately while the current heading catches up gradually.

YOUR TURNCompare condition A with B, then inspect what changed.
DRAG THE SIGNAL AROUND THE ANT
SIGNAL SLOPE 1.08 SENSOR REACH 92 PX
Accessible experiment transcript

Five forward samples compare a synthetic pheromone slope; the strongest valid sample becomes a gradual steering target. Canvas gesture: drag the signal around the ant.

Drag the signal around the same moving ant. The strongest ray changes immediately, but steering eases toward it instead of snapping to a new heading.

Pheromone priority is a state switch. An outbound ant reads the food field. An ant carrying food reads the home field. If the actual food or nest is close enough to sense directly, the physical target overrides both fields.

The best ray wins only if it clears the temperament’s confidence threshold. If no sample is convincing, the ant keeps exploring. This is already more purposeful than the empty-field ant, but the improvement reveals the next failure: there is nothing to sense until a discovery leaves something behind. One ant can learn nothing from another ant’s lucky trip.

The ground becomes the colony’s notebook

A searching ant now deposits home evidence as it travels. Once it picks up food, it follows that evidence back and deposits food evidence in the opposite direction. The route is not stored inside any ant. It survives temporarily in the world.

LIVE MODEL / ant memory

A private trip becomes public memory

INTERACTIVE
WORLD SO FAR
  1. Movement before memory ✓
  2. Five local samples ✓
  3. A trip becomes evidence +
QUESTION How can one private trip remain useful after the ant has left?
COMPARE TWO CONDITIONS
WATCH FOR

Draw a trail across the field. Each mark should widen, fade, and eventually disappear instead of becoming permanent advice.

YOUR TURNCompare condition A with B, then inspect what changed.
DRAW A TRAIL; WATCH IT SPREAD AND FADE
EVAPORATION 88% DIFFUSION 18%
Accessible experiment transcript

A successful trip deposits evidence that spreads to neighboring cells and fades with age. Canvas gesture: draw a trail; watch it spread and fade.

Draw a trail directly on the field. Diffusion widens the readable corridor while evaporation removes advice that stops receiving reinforcement.
MODEL / WALKTHROUGHOne field update
Pt+1(x)=(1 − ρ)[Pt(x) + D∇²Pt(x)] + ΔPt(x)

Update one patch of ground, then repeat the same operation across the field.

  1. 01
    Read the current memoryP at time t is the signal already stored at this location.
  2. 02
    Share it with nearby groundThe diffusion term moves a fraction toward neighboring cells. D controls how widely it spreads.
  3. 03
    Let old evidence fadeMultiplying by one minus rho removes a small fraction. A larger rho means faster forgetting.
  4. 04
    Add what happened nowDelta P is the fresh signal deposited by ants during this update.
  5. 05
    Use the result nextThe combined value becomes P at time t plus one—the field the ants read on the next step.
Existing evidence diffuses, then decays; new local deposits are added afterward. The implementation applies this update to home, food, and doubt buffers.

Decay is doing real work. Permanent marks would fill the world with obsolete recommendations. Instant evaporation would make one ant’s luck useless to the next. Useful shared memory lives between those failures.

The loop is small:

  1. leave home and deposit a way back;
  2. wander until food or useful food evidence is nearby;
  3. carry one piece home while reinforcing the successful route in proportion to its value;
  4. unload, turn around, and search again.

No ant owns the route. The route exists only while enough trips keep confirming it.

A working route is not necessarily a good route

Shared memory creates another visible flaw: the first route that works can dominate even when it wanders. The simulation therefore measures each completed trip against the direct distance between food and nest. Efficient trips deposit more useful evidence than long detours.

LIVE MODEL / ant route choice

Repeated shortcuts become preferred

INTERACTIVE
WORLD SO FAR
  1. Movement before memory ✓
  2. Five local samples ✓
  3. A trip becomes evidence ✓
  4. Short routes reinforce faster +
QUESTION If both paths work, how can repeated trips make one path more likely?
COMPARE TWO CONDITIONS
WATCH FOR

Click either corridor to complete another trip. Its evidence and the probability of choosing it next should rise together.

YOUR TURNCompare condition A with B, then inspect what changed.
CLICK A ROUTE TO COMPLETE ANOTHER TRIP
SHORT ROUTE TRIPS 5 TRIPS LONG ROUTE TRIPS 8 TRIPS
Accessible experiment transcript

Two valid corridors compete. Repeated efficient trips make the shorter route increasingly likely without a global map. Canvas gesture: click a route to complete another trip.

Both corridors reach the same destination. Click either path to complete another trip and watch local evidence—not a central planner—change the next route probability.

The shorter corridor does not win because an ant can calculate the global shortest path. It wins because it completes more reinforcing trips in the same time and each efficient return contributes a stronger deposit. This follows the useful idea behind nonlinear trail choice—stronger evidence should become disproportionately persuasive—without pretending the model recreates any one species exactly. (Beckers et al., 2003)

The route now improves itself, but it still trusts old success too much. Move the food or place an obstacle across the corridor and ants can keep following a strong signal into nothing.

A strong smell is not proof

The first version had no explicit answer to a false-positive trail. An ant would keep selecting whatever food signal remained until evaporation or random motion finally freed it. Severing a route exposed the same weakness, and the field edges made it worse: position was clamped at the border while the ant took too long to turn, so it could pace along the wall indefinitely.

The new policy exits early. Each ant carries a short spatial memory and a small commitment ledger: how long it has followed this signal, the strongest evidence recently seen, and whether it is revisiting the same patch. A collapsing signal, a loop, an overlong commitment without finding food, an obstacle, or an edge contact triggers recovery. The ant turns away, temporarily ignores attractive trails, and leaves a short-lived purple doubt mark. Other ants subtract that local warning from their five ray scores.

LIVE MODEL / ant recovery

Turn trusted advice into doubt

INTERACTIVE
WORLD SO FAR
  1. Movement before memory ✓
  2. Five local samples ✓
  3. A trip becomes evidence ✓
  4. Short routes reinforce faster ✓
  5. Bad advice must expire +
QUESTION What should happen when yesterday’s strongest trail ends at an obstacle?
COMPARE TWO CONDITIONS
WATCH FOR

Drag the obstacle onto the trusted trail. With recovery enabled, the ant should exit early and leave doubt near the dead end.

YOUR TURNCompare condition A with B, then inspect what changed.
DRAG THE BLOCK ACROSS THE TRUSTED TRAIL
OLD TRAIL STRENGTH 92% DOUBT DECAY 0.9 S
Accessible experiment transcript

A trusted trail ends at an obstacle. Declining evidence triggers a turn, and a temporary doubt mark discourages the same dead end. Canvas gesture: drag the block across the trusted trail.

The world still contains movement, sensing, memory, and route preference. Drag the obstacle onto the proven corridor: declining evidence triggers an early exit and a temporary doubt trail makes the alternative useful.

That mechanism is inspired by real negative feedback, not copied wholesale. Pharaoh’s ants can place a “no entry” signal at unrewarding branches, while other ant systems reduce positive pheromone deposition under bad local conditions such as crowding. (Robinson et al., 2005; Czaczkes et al., 2013) Here, one fast-decaying doubt field gives the experiment a visible way to say, “this advice stopped working.”

Edges now participate in the same logic. The sensing fan assigns increasing risk before a ray leaves the habitat, steering the ant inward before contact. If contact still happens, its heading reflects immediately and the boundary receives a doubt mark. It no longer waits against the wall for a slow turn to finish.

At this point every addition answers a failure created by the previous one. The remaining question is whether those local fixes still cooperate when dozens of ants, multiple food values, moving targets, and obstacles share one field.

The pattern I did not draw

My favorite moment in the original project was what I started calling “laminar flow.” I do not mean the code became a fluid simulation. I mean that many jittery, private decisions began to look like a coherent stream between food and nest.

I had written movement, sensing, pickup, return, and decay. I had not drawn that stream. Seeing it emerge was the payoff.

Tuning the rules felt less like polishing constants and more like giving the colony a temperament. A disciplined colony trusts signals and settles quickly. A curious colony wanders farther and keeps alternatives alive. The adaptive setting sits between them. Trail persistence still controls memory, but temperament controls how readily an individual believes it. The same fascination is why I later built boids: simple agents become interesting when their local rules overlap.

Why keep the old flat view?

The isometric habitat makes the colony feel alive, but it also hides information behind perspective. The original top-down idea remains the clearest way to inspect density, direction, and the full trail at once. I kept it as an alternate experience instead of replacing it with a prettier camera.

That distinction matters to me: a visualization should answer a question. The orbitable world answers, “What would this little system feel like?” The signal view answers, “What information are the ants changing?” The map answers, “Where is the pattern actually forming?” One simulation can support all three without pretending one camera is universally best.

Rebuilding the source UI without multiplying the work

The simulation now keeps behavior separate from presentation. A seeded colony engine owns the ants, food sources, obstacles, delivery value, and two diffusing pheromone buffers. Three.js renders the habitat with one orthographic camera, orbit controls, instanced ant bodies, legs, antennae, cargo, sharp labels anchored inside the world, and a point cloud for the signal field. The alternate canvas renderer reads those same objects into the flat map.

The article also mounts only one iframe for all three figures. As you scroll, that iframe moves to the active slot and receives a view message. Offscreen work pauses. On smaller or resource-constrained devices, the reading preset lowers pixel density and caps the population before it removes behavior. That keeps the “same colony” claim literal and avoids running three animation loops just to tell one story.

The older Svelte port experimented with typed entities and a quadtree for spatial lookup. This rebuild uses fixed-size trail buffers for the environmental memory and instancing for repeated ant geometry. Those choices fit the questions this version asks: sample a local field cheaply, keep many agents visible, and make the trail itself legible.

Break a good route on purpose

Once a route works, the most revealing thing to do is interrupt it. Block busy trail places a log or rock across the strongest current corridor. The obstruction masks the pheromone field beneath it, steers ants away from its footprint, and turns yesterday’s good advice into a dead end.

That makes reorganization visible rather than theoretical. Ants pile up briefly, exploratory trips become useful again, and a competing corridor begins to collect enough reinforcement to take over. Up to three obstacles can be added before the control clears the field for another experiment.

The closer animation serves the same explanation. Legs cycle while an ant travels, antennae search ahead, cargo rises during pickup, and it lowers into the nest during unloading. I kept those gestures compact so the group remains readable when dozens of ants share a trail.

There is still plenty to explore. I would like to compare temperaments quantitatively, add colony-to-colony competition, and make the obstacle tools more spatially editable. For now, the lab reaches the part I originally cared about: ants discover food without a route, turn repeated trips into shared evidence, and recover when that evidence stops being useful.

Put the pieces together

The capstone below recombines the controlled examples. These are three windows onto one running colony: the orbitable habitat, the environmental memory field, and the original top-down map. Moving food or blocking a route in one window changes the others.

SESSION 01 / 03

Run the complete colony

ORBIT / LIVE
Orbit the habitat, compare nearby crumbs with richer fruit, and move the rich source. Movement, sensing, memory, route choice, and recovery now operate together.
SESSION 02 / 03

Inspect the colony’s public memory

MEMORY / LIVE
Filter Ant Vision by search, signal, return, and recovery. Pause and select one ant to read its decision without chasing a moving unit.
SESSION 03 / 03

Flatten the same session into a field map

2D FIELD / LIVE
The agents, deliveries, food, obstacles, and pheromone buffers are unchanged. Only the renderer switches to the project’s original top-down language.

What this project taught me

There is a limit to how far I can predict emergent behavior from reading the rules. I can define the agents, their information, the boundaries, and the feedback. I can make a hypothesis about what the group will do. I still have to run it and watch.

That is what I want this project to say about me. I like building systems whose parts remain understandable while their interactions create something I did not script frame by frame. Randomness is not always an error to remove. Sometimes it is the first ant that finds the food.

The expanded source lab keeps Habitat, Signals, and 2D Field available together. The repository contains the simulation engine, both renderers, and the archived experiments that led here.