No description
Find a file
Jared Miller 5d25218433
Prevent ants from picking up the surface they walk on
Angle noise (±12° from wander) caused the ahead-cell pickup check
to sample into the sand cell directly below the ant. Ants were
grabbing sand on their first frame of existence.

Fix: skip powder pickup when the ahead cell equals the cell directly
below (the walking surface). Food pickup is still allowed from any
adjacent cell. Diagonal dig pickup still works since the DIG priority
angles ants at ~40° which targets a diagonal neighbor, not directly
below.
2026-03-12 10:16:14 -04:00
docs Add ant behavior overhaul implementation plan 2026-03-11 20:35:11 -04:00
public/textures Organize as an updated bun project 2026-03-09 09:55:24 -04:00
src Prevent ants from picking up the surface they walk on 2026-03-12 10:16:14 -04:00
.gitattributes Initial commit 2022-06-24 16:44:44 +03:00
.gitignore Initial implementation 2022-06-26 12:34:16 +03:00
biome.json Add tooling setup with biome, justfile, and check pipeline 2026-03-09 10:39:31 -04:00
bun.lock Add tooling setup with biome, justfile, and check pipeline 2026-03-09 10:39:31 -04:00
CLAUDE.md Update CLAUDE.md for ant behavior overhaul 2026-03-11 22:50:10 -04:00
index.html Add camera view mode toggle between side and top-down 2026-03-11 17:45:47 -04:00
justfile Add neocities deploy 2026-03-10 10:53:44 -04:00
LICENSE Initial commit 2022-06-24 16:44:44 +03:00
package.json Add tooling setup with biome, justfile, and check pipeline 2026-03-09 10:39:31 -04:00
README.md Document new ant behaviors 2026-03-09 11:26:06 -04:00
tsconfig.json Organize as an updated bun project 2026-03-09 09:55:24 -04:00
vite.config.ts Organize as an updated bun project 2026-03-09 09:55:24 -04:00

ants-simulation

GPU-accelerated ant colony simulation built with three.js and GLSL shaders. All simulation logic runs entirely on the GPU — no JavaScript-side physics loop.

Live demo

ants collecting food

How it works

Ants emit two types of pheromones: to-home (left by ants searching for food) and to-food (left by ants carrying food). Ants searching for food follow to-food trails; ants carrying food follow to-home trails.

Each ant carries a limited pheromone inventory. Picking up food or reaching home refills the inventory; each pheromone deposit drains it. This prevents ants that wandered too far from leaving misleading trails — their pheromone runs out, so their trails naturally fade.

Pheromone trails diffuse across neighboring cells and decay over time. The simulation also supports a repellent pheromone channel (independent decay rate and diffusion radius) for future use.

Controls

  • Q — paint home
  • W — paint food
  • E — paint obstacles
  • R — erase
  • Mouse wheel — zoom
  • Click + drag — pan

Architecture

The simulation runs as a chain of GPU render passes using ping-pong render targets:

  1. Pheromone blur/decay — diffuse and evaporate all pheromone channels
  2. Ant compute — update each ant's position, direction, and carrying state (MRT: writes primary + extended state simultaneously)
  3. Discretize — map continuous ant positions onto the world grid
  4. World update — merge ant deposits into the pheromone grid
  5. Colony stats — CPU readback of aggregate colony state (forager ratio)
  6. Draw — user painting input
  7. Screen — final composited output

Per-ant state (2 textures via MRT)

Texture R G B A
Primary pos.x pos.y angle packed(storage, isCarrying)
Extended personality cargoQuality pathIntDx pathIntDy

World state (RGBA Float32)

Channel Data
R packed cell metadata (food/home/obstacle flags + terrain type + food quality)
G to-home pheromone
B to-food pheromone
A repellent pheromone

Development

Requires bun.

bun install
bun run dev       # start dev server
just check        # lint + typecheck + test

References

License

MIT