This project implements a physarum slime mold simulation using Rust and WGPU.
If your browser supports WebGPU you can play with the project here. Currently it just works on Chrome on Desktop, some other browsers may have developer settings to enable WebGPU support.
There are many descriptions of this algorithm available online, for further reading I recommend:
- Characteristics of pattern formation and evolution in approximations of physarum transport networks - a paper describing the operation of the simulation.
- Sage Jenson's work on a physarum simulation.
- Rust is installed and
cargo
is available in the path- wasm-pack is install via cargo (works for Mac ARM vs npm)
cargo install wasm-pack
- wasm-pack is install via cargo (works for Mac ARM vs npm)
npm
is installed- The modules are installed
npm -i webpack-cli
npm run serve
- Open localhost::8080 in the browser, optionally specifying parameters
width
intheight
intstep_size
floatrotate_angle
floatsense_angle
floatsense_offset
floatnum_agents
intfg_colour
string e.g. "EEFF89"bg_colour
string e.g. "4599AA"decay
floatdeposit
floatrunning
boolextra_controls
bool
e.g. localhost:8080?fg_colour=EEFF89&bg_colour=4599AA&width=400&height=400
- Agents (positions + headings). Access by index. Double-buffered
- Chemo 2d texture. Accessed by x,y position. Double-buffered
- New dots 2d texture representing the agent positions with a dot drawn at each.
-
Draw positions - render pipeline
- Input: Agents[A]
- Output: new dots 2d texture
-
Deposit - compute pipeline
- Input: new dots
- Input: Chemo[0]
- Output: Chemo[1]
-
Diffuse - compute pipeline
- Input: Chemo[1]
- Output: Chemo[0]
-
Update agents - compute pipeline
- Input: Agents[A]
- Input: Chemo[0]
- Output: Agents[B]
swap A & B each frame
- Add an input 2d texture which can be used to weight towards regions etc. Ideas:
- A layer which modifies the decay (e.g. for topology)
- A layer which has adds a constant chemo to an area (cornflake)
- A blocking layer which prevents any chemo in an area (no-go)
- Have groups within the population and different attractant areas/points for each.