Backgrounds

Mycelium

A slime mould foraging in the dark. Every other field here is a differential equation on a grid; this one is a population — up to a million agents, each carrying a position and a heading, sampling the trail ahead of itself, turning toward whatever smells strongest and laying down more of it as it goes. The veins, the junctions and the slow reorganisation are nowhere in the code.

Install

bun add ogl

Then copy 2 files into your project:

  • components/registry/mycelium/mycelium.tsx
  • hooks/use-animation-loop.ts

Props

PropTypeDefaultDescription
agentCount"65k" | "262k" | "1M""1M"How many agents forage the field, in discrete steps rather than on a slider — each value reallocates the state textures and rebuilds the point geometry, which a slider would do on every pixel of a drag. Against a fixed 1024px field this is a density: a million closes the web into fine reticulation, and a quarter of that is the same behaviour drawn as a few sparse trunks. Step down if the frame rate needs it.
speednumber55Forward travel per second, against the 1024px field. Push it far past the sensor distance and an agent steps clean over a vein without ever sensing it — the colony looks fast and builds nothing.
sensorDistancenumber7How far ahead the three sensors sit, measured against the trail map rather than the canvas so the structure holds its scale on a narrow strip. Short is myopic and knots; long lets an agent commit to a vein it can already see.
sensorAnglenumber24How far off its heading an agent looks when it samples left and right. This one control decides the topology: narrow makes long parallel veins that rarely meet, wide makes a dense web that merges everywhere. Past about 45° both flanks read the same trail and the colony loses its ability to choose.
turnSpeednumber24How sharply an agent can steer, in radians per second. The interesting band is where this is just under what the sensor angle asks for, so agents are always slightly behind the decision they have made. Too low and they cannot follow their own trail at all.
wandernumber13Random walk added to every heading, in radians per second — exploration against exploitation. Trail-following is pure positive feedback, so at zero the colony converges onto two or three trunk roads within a minute and the rest of the field goes black. This is the noise that keeps leaking agents into empty space, where they seed the next generation of branches.
decaynumber0.97Fraction of the trail surviving each 60th of a second — the colony's memory. Below about 0.95 nothing persists long enough for a second agent to find it and no structure forms; above 0.995 every path ever taken stays lit and the map fogs over.
diffusenumber0.35Blend toward the blurred neighbourhood. Diffusion is what lets a vein be found from beside it rather than only from on it — at zero the trails are one texel wide, invisible to a sensor not already on them, and nothing ever aggregates.
depositnumber0.03Trail laid down by one agent in one step. Against decay this is the whole economy — a cell settles at deposit over one-minus-decay, so the pair decides whether open ground stays dark while the veins pin bright, or the entire field saturates into one flat sheet.
attractnumber0.6Strength of the food source under the pointer. It is laid into the trail map rather than applied as a force, so the colony has to find it and route to it over several seconds — the veins thicken toward your cursor the way they would toward an oat flake, instead of the swarm snapping to it. 0 turns it off.
spawn"ring" | "scatter" | "disc""scatter"Where the population starts and which way it faces. Scatter is uniform and low-density, so the web self-organises within a couple of seconds. Ring faces inward and has to resolve its own collision first — slower to settle, and the only one where you can watch the first branches being forced.
trailColorstring (hex)"#a855f7"The trail itself.
backgroundstring (hex)"#07060c"The dark the network grows against.
glownumber0.8Extra light on the densest strands, where several trails have piled onto the same cell.

What It Demonstrates

Loop
An animation that repeats, a set number of times or infinitely.
Idle animation
Subtle motion that plays while an element is just sitting there, waiting to be interacted with.
Hover effect
Visual change when the cursor moves over an element.
Hardware acceleration
Animating transform and opacity lets the GPU keep motion smooth.
Compositing
Letting the GPU move or fade an element on its own layer without redoing layout or paint.

Related Components

Appears In