physarum

repository·main·Indexed 21 days ago

https://github.com/fogleman/physarum

A 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.

Tokens
602
Snippets
2
Records
5
Agent score
26%

What's inside physarum

  1. Overview of Physarum Transport Networks

    main
    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.
  2. Use the physarum viewer CLI

    main

    The cmd/viewer tool 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

    KeyAction
    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).
  3. Manage simulation state and visualization with Texture

    main

    The Texture type is used to map the raw simulation data from the physarum.Model into 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.
  4. Run the Physarum simulation via CLI

    main

    The physarum command 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 via physarum.Run().

    # Run the simulation
    physarum