pyLEAFS.viewer module

Interactive matplotlib viewer for a 2d simulation.

Controls

spacebar

Pause / resume the simulation.

click empty space

Add a new agent at the cursor (works while paused or running).

click on an agent

Select it for inspection: a highlight ring appears, a side panel shows its state, and its recent trajectory is drawn as a trail. Click empty space again to deselect (or to add an agent there).

The viewer reads the simulation through its public attributes only; it never reaches into private buffers. It targets D == 2; a 3d viewer is a later layer.

class pyLEAFS.viewer.Viewer(sim, steps_per_frame=4, select_radius=2.0, trail_length=200, interval=30)[source]

Bases: object

An interactive viewer for a 2d Simulation.

Parameters:
  • sim (Simulation) – The simulation to display. Must be 2-dimensional.

  • steps_per_frame (int, optional) – Simulation steps advanced per rendered frame (default 4).

  • select_radius (float, optional) – Click-to-select tolerance in physical units; a click within this distance of an agent selects it, otherwise it adds a new agent (default 2.0).

  • trail_length (int, optional) – Number of past positions retained for the selected agent’s trail (default 200).

  • interval (int, optional) – Matplotlib animation interval in milliseconds (default 30).

Examples

>>> from pyLEAFS import Simulation, Viewer
>>> Viewer(Simulation.forager(seed=0)).play()
play()[source]

Open the window and run until it is closed.