No description
Find a file
Jared Miller cd8a4ade82
Spawn ants on sand surface in side view mode
Add VIEW_MODE_SIDE define to common shader defines so shaders can
branch on view mode via preprocessor. In side view, ants init by
scanning downward from the top to find the first non-air cell, then
spawn one pixel above it facing downward. Top view keeps the original
center spawn with random angle.
2026-03-11 14:35:43 -04:00
docs Add ant farm sand physics implementation plan 2026-03-11 12:44:24 -04:00
public/textures Organize as an updated bun project 2026-03-09 09:55:24 -04:00
src Spawn ants on sand surface in side view mode 2026-03-11 14:35:43 -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 Document new ant behaviors 2026-03-09 11:26:06 -04:00
index.html Change from blue to red 2026-03-10 11:04:28 -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