Ant Kingdom
A glass ant farm that digs itself: carved tunnels grow grain by grain, and amber pheromone trails pull a living line of ants to your sugar.
This world didn't start here.
It needs WebGPU or WebGL2: try a recent Chrome, Edge or Safari, or open it on its own.
Open on its own
Goal & tips
Goal Grow the colony from 30 ants to 500 and dig six different chambers: nursery, food store, queen's room and more.
Try this
- Drop sugar on the garden and watch a trail form back to the nest
- Pour water and the ants carry the brood up to safety
- Poke a tunnel in: they dig it out again
- Turn Speed up to 4× or 16×: at 1× the kingdom takes about half an hour
Keys 1–5 Food, Water, Poke, Torch, Dig+ / − speedF red-ant raidG rainC Cinema
Secret The ants build something special for their queen. Who has seen it?
Show hint (spoiler)
Keep the queen well fed (plenty of food in store) until the colony passes 300 ants. The ants carve a tiny crown into a chamber wall and she moves in.
The prompt
Build "Ant Kingdom", a playable miniature world: a tall glass ant-farm slab where a colony digs tunnels and chambers live, as ONE self-contained HTML file.
It must be **beautiful above everything**, like a premium animated film: a crisp, warm, slightly macro-photography look: grainy layered sand, glossy little ants, soft depth of field. Great animation on everything that moves: nothing pops, snaps or teleports; things grow, ease, overshoot a little and settle. Calm and satisfying to play, spectacular to watch.
## Tech
* three.js r170 with WebGPURenderer (automatic WebGL2 fallback). Load it with an importmap from jsDelivr: map "three", "three/webgpu" and "three/tsl" to `three@0.170.0/build/three.webgpu.min.js`, and "three/addons/" to `three@0.170.0/examples/jsm/`.
* Use TSL node materials, OrbitControls from the addons, and a subtle BloomNode pass (strength ~0.4, threshold ~1.5) so only emissive things glow (the torch beam, sugar sparkles, the queen's chamber glow at night).
* No external assets. Every texture is drawn on a canvas or generated as pixel data at startup. Every sound is synthesized with WebAudio. The only network requests are three.js from jsDelivr and the Fredoka font from Google Fonts; if the font fails to load, fall back to a system rounded sans-serif without breaking anything.
* Start the HTML with `<!doctype html>` and `<meta charset="utf-8">`.
* It must run inside a sandboxed iframe (`sandbox="allow-scripts allow-pointer-lock"`, no `allow-same-origin`). There, `localStorage` and cookies throw a SecurityError: wrap every storage access in `try/catch` and keep values in memory instead. Do not use `alert`, pop-ups or top-level navigation.
* Neutral tone mapping, soft 2048 shadow map (1024 on phones).
* Known three r170 pitfalls, avoid them:
* the scene background is drawn after transparent objects, so draw the sky/backdrop as a mesh (or give transparent sky objects `depthWrite: true`), or they disappear;
* never `.clone()` a CanvasTexture (the clone uploads black); create separate textures or use DataTexture;
* never let a helper overwrite a shared temp vector that its caller is still using.
* The simulation runs on a fixed 60 Hz timestep and is frame-rate independent. At low frame rates, drop simulation time instead of exploding.
* A quality scaler lowers the pixel ratio, then particle counts, when frames get slow.
* Respect prefers-reduced-motion: softer shake, slower camera moves.
## Priorities
Build in this order and finish each tier properly before the next. A polished tier 1 beats a broken everything.
1. **Must be excellent:** the slab (sand grid you can see into), ants walking, digging and carrying sand grains, tunnels growing, food trails with pheromones, the demo mode.
2. **Must work:** roles (diggers, foragers, nurses, soldiers), the queen and brood, flooding and rescue, cave-ins and repair, the colony meter and chambers, sound, the card UI, camera.
3. **Polish:** the rival raid, rain on the garden, chamber labels, the light/torch tool, the time-lapse speed.
Never ship a feature half-working: if a tier-3 feature can't be done well, leave it out cleanly.
## The ant farm
* A tall, thin **glass slab** (about 8 wide × 10 tall × 1 deep) in a wooden frame with a little lid, standing on a desk with a soft backdrop. Through the front glass you see the inside like a cross-section.
* Inside: **layered sand and soil** (tan, ochre, dark loam, a few pebbles and roots) as a 2D grid of cells (about 200 × 260) rendered as a textured surface with depth shading so tunnels look carved. At the top, a thin strip of **garden**: grass, a small plant, a twig, a leaf.
* Tunnels and chambers are empty cells with soft shadowed edges; excavated sand grains are carried out and piled as little mounds on top.
## Ants
* **200–400 ants** (instanced, 6-legged walk cycle with antennae wiggling, glossy dark brown with a highlight), each with a simple state machine. Roles (with subtle colour tints visible when zoomed in):
* **diggers** extend tunnels downward and sideways, carrying grains up to the surface;
* **foragers** go out to the garden, find food and lay **pheromone trails** home;
* **nurses** move eggs, larvae and pupae between chambers and feed them;
* **soldiers** (bigger heads) guard the entrance and the queen.
* **The queen** (large) lives in the deepest chamber, lays eggs every so often. Eggs → larvae → pupae → new ants; the colony grows.
* Ants follow pheromone gradients, avoid each other a little, and form satisfying **lines** to food. They never walk through solid sand.
* **Chambers** form when diggers widen a tunnel junction; each gets a purpose based on what is stored there: nursery, food store, queen's room, rubbish heap, resting hall, soldiers' hall. Labels fade in briefly when a chamber is first used.
## Tools (card, keys 1–5)
* **Food:** tap the garden to drop a crumb, a sugar cube or a leaf; scouts find it, a trail forms, and a line of ants carries it piece by piece down to the food store.
* **Water:** pour on top: water **seeps down** through the sand (darkening it) and floods low tunnels; nurses **rescue the brood** upward, ants form a little living raft; the water drains over time.
* **Poke:** tap a tunnel to cause a small **cave-in**; ants rush to dig it out and repair it.
* **Torch:** shine a light beam; ants avoid the light and move eggs away from it.
* **Dig:** draw a starter tunnel with the finger; the ants adopt and extend it.
## Events
* **Rival raid:** a few red ants enter from the side; soldiers meet them at the entrance and push them back (wrestling, no gore); a toast reports victory.
* **Rain** on the garden: drops, a soaked top layer, ants close the entrance.
* **Time-lapse** speed control (1×, 4×, 16×) so the colony visibly grows.
## Goal and milestones
* **Colony** meter: population (start 30, goal 500) and chambers (goal 6 kinds). Show both, plus food stores.
* At the goal: a celebration: all ants pause and wave antennae, the queen's chamber glows, confetti-like sand sparkles.
Milestones (toasts, once each): "First tunnel", "First trail", "Sugar rush", "First new ant", "Flood rescue", "Raid repelled", "Six chambers", "Ant kingdom".
## Easter egg
When the queen is well fed and the colony passes 300, the ants carve a tiny **crown shape** into one chamber wall and the queen moves in. Toast: "Long live the queen." Never hint at it in the UI.
## Interface
A light, playful UI that never covers the world. On phones the card becomes a compact bottom sheet.
* Top left:
* small caps "POKEABLE · WORLD";
* a big chunky rounded heading on two lines, "Ant" / "Kingdom", in Fredoka from Google Fonts, dark ink, with a tiny ant walking along the top of the letters;
* caption "Feed them. Watch them build.".
* Top right: a live status dot with "WEBGPU · LIVE" (or "WEBGL2 · LIVE"), a speaker pill button (ON / MUTED), and "PAUSED" when paused.
* Right card "Colony": about 240 px wide, off-white, 20 px corners, soft shadow, no hairlines, amber (#e09a2c) accent, collapsible to a small pill. Contents:
* population as a big rolling number with a bar to 500, chambers found (6 icons), food stores
* tool picker: Food, Water, Poke, Torch, Dig, each with a drawn icon and its key number
* event buttons: Raid, Rain
* sliders with monospace value chips: Speed (1×–16×), Food richness, Sound (master volume)
* switches: Pheromone trails (off), Chamber labels (on), Slow motion (¼ speed), Cinema
* buttons Reset and New (random seed), a dark full-width Pause/Resume pill, and the world's number ("No. 0001").
* Bottom left: a one-line hint that changes with the tool:
* Food: "Drop food on top. Watch the trail form."
* Water: "Pour water. They will save the eggs."
* Poke: "Collapse a tunnel. They will fix it."
* Torch: "Shine a light. Ants avoid it."
* Dig: "Draw a starter tunnel."
* Bottom right: a collapsible "How it works" panel, 5–6 plain lines on the sand grid and digging, pheromone trails, ant roles, the brood cycle, chambers, the camera controls, and synthesized sound.
* Toasts at the top centre for milestones and events.
* Keys: 1–5 tools, F raid, G rain, +/- speed, Space pause, R reset, N new, M mute, S slow motion, C cinema, 0 reset view, Esc stop follow / exit cinema.
## Camera
* OrbitControls with damping and zoom to cursor, within sensible limits (mostly front-on; the slab can turn about 35° each way).
* Double-click any ant (the queen too) to follow it; Esc or 0 stops.
* Camera bar (floating pill, bottom right of the scene area): zoom −, a zoom % readout, zoom +, rotate left, rotate right, reset; button moves tween smoothly.
* The default framing fits the whole world into the free area, accounting for the card and title.
* **Cinema (`C`):** hides all UI and slowly orbits the camera.
## Sound
* WebAudio only. Create the AudioContext on the first gesture and never before.
* Master gain feeds a compressor, so rapid actions never clip. Limit voices (about 16) and wrap every call in try/catch so a failing audio call never breaks the world.
* Loops: a soft rustling ambience whose density follows the number of ants moving, a gentle earthy hum, rain when raining.
* One-shots: tiny sand-grain ticks when digging, crumbling for cave-ins, a sweet sparkle when food is found, a water trickle for pouring, little chitters for the raid, a soft pop when an ant hatches, chimes for milestones.
## Demo mode (required)
If the URL has `?demo=1` (or `#demo`), auto-play a deterministic 4.0 s loop:
* Rules:
* Hide all UI and the cursor; never create an AudioContext.
* Fixed quality, default seed, a colony of ~120 ants with some tunnels already dug, default camera, no OrbitControls.
* Drive the simulation from real elapsed time with the fixed timestep, and restart from the identical state every 4.0 s.
* Start moving within 1 s of load, and stay readable at 15 fps.
* Timeline:
* 0.0–1.0 s: ants walk the tunnels; a sugar cube drops onto the garden.
* 1.0–2.5 s: a scout finds it and a line of ants forms along a glowing trail.
* 2.5–3.5 s: ants carry sugar pieces down while a digger extends a tunnel with a spray of grains.
* 3.5–4.0 s: the queen lays an egg; the colony keeps moving.
## Before you finish, check
* Ants never walk through solid sand; tunnels, chambers and mounds grow believably; cave-ins get repaired.
* Food trails form and dissolve; flooding seeps and drains; brood rescue happens.
* The brood cycle grows the colony; chambers get purposes and labels.
* The raid, rain, torch, time-lapse speeds and the Easter egg.
* Every tool, slider, switch, button and key; follow mode; Cinema; pause and resume; resizing to phone width.
* Sound behaviour.
* It works inside `<iframe sandbox="allow-scripts allow-pointer-lock">` with no errors (storage blocked).
* `?demo=1` matches the timeline.
* No console or WebGPU validation errors, and it stays smooth on a mid-range laptop.
Put the living trail of ants and the tunnels growing in real time first. It should be impossible to look away.