physarum
repository·main·Indexed 21 days ago
https://github.com/fogleman/physarumA particle-based simulation of Physarum polycephalum (slime mold) transport networks implemented in Go. Includes a core simulation engine and an OpenGL-based interactive viewer for real-time visualization and manipulation of generative network patterns.
What's inside physarum
- Physarum Transport Networks is a particle-based simulation inspired by the Physarum polycephalum slime mold. It uses a generative algorithm to create complex transport network patterns from simple particle behaviors.
Run the Physarum simulation
mainTo run the Physarum transport network simulation, use the Go toolchain to execute the main entry point located in
cmd/physarum/main.go.go run cmd/physarum/main.goUse the physarum viewer CLI
mainThe
cmd/viewertool provides an interactive OpenGL-based visualization of the physarum simulation. It allows you to observe the transport networks in real-time and manipulate the simulation using keyboard shortcuts.Controls
Key Action SpaceReset: Generates a new model with random configurations and a new palette. RStart Over: Resets the current simulation state while keeping the same configuration. PNew Palette: Generates and applies a new random color palette. OShuffle Palette: Randomly shuffles the existing color palette. AAuto Level: Automatically adjusts the color levels based on the current data percentiles (0.001 to 0.999). Manage simulation state and visualization with Texture
mainThe
Texturetype is used to map the raw simulation data from thephysarum.Modelinto a visual format suitable for OpenGL rendering. It handles color palettes, gamma correction, and automatic level adjustment.Key Methods
NewTexture(): Initializes a new texture with OpenGL bindings.Init(width, height, count int): Prepares the texture buffers for a specific simulation size and number of configurations.SetPalette(palette physarum.Palette, gamma float32): Applies a color palette with gamma correction.ShufflePalette(): Randomly reorders the colors in the current palette.AutoLevel(data [][]float32, minPercentile, maxPercentile float64): Calculates min/max values for each data grid based on specified percentiles to optimize color mapping.Draw(window *glfw.Window, data [][]float32): Updates the texture buffer with the provided simulation data and renders it to the window.
Run the Physarum simulation via CLI
mainThe
physarumcommand is the primary entrypoint for executing the Physarum transport network simulation. It initializes the simulation environment with a random seed and invokes the core simulation engine viaphysarum.Run().# Run the simulation physarum