world_visualizer

Pyglet-backed live visualization

Provides video, video_debug, and all_linkages_video. Lazy-imported from the package root — only pulls in pyglet at access time, so headless environments aren’t penalized.

Visualization for walking linkage simulations.

Uses Pyglet for hardware-accelerated rendering with pymunk integration.

class leggedsnake.world_visualizer.CameraSettings

Bases: TypedDict

dynamic_camera: bool
fps: int
class leggedsnake.world_visualizer.VisualWorld(space: Space | None = None, road_y: float = -5, headless: bool = False)

Bases: World

Same as parent class World, but with Pyglet rendering.

__init__(space: Space | None = None, road_y: float = -5, headless: bool = False) None
batch: pyglet.graphics.Batch
init_visuals(colors: list[float] | list[list[float]] | ndarray[tuple[Any, ...], dtype[floating[Any]]] | None = None) list[Any]
reload_visuals() list[Any]
run(duration: float = 30.0) None
visual_update(time: list[float] | float | None = None) tuple[float, float] | None
window: pyglet.window.Window | None
leggedsnake.world_visualizer.all_linkages_video(linkages: list[Any], duration: float = 30, save: bool = False, colors: ndarray[tuple[Any, ...], dtype[floating[Any]]] | list[float] | list[list[float]] | None = None, dynamic_camera: bool = False) None

Simulate linkages with video output.

Parameters:
  • linkages (list) – Walkers, DynamicLinkages, or legacy Linkages to simulate.

  • duration (float) – Duration in seconds.

  • save (bool) – Save as video (not yet implemented for Pyglet).

  • colors (list) – Opacity or color per linkage.

  • dynamic_camera (bool) – Follow one strider vs. larger view.

leggedsnake.world_visualizer.im_debug(world: VisualWorld, linkage: DynamicLinkage) None

Use pymunk debugging for visual debugging.

leggedsnake.world_visualizer.smooth_transition(target: tuple[tuple[float, float], tuple[float, float]], prev_view: tuple[tuple[float, float], tuple[float, float]], dampers: tuple[tuple[float, float], tuple[float, float]] = ((-10, -5), (10, 5))) list[list[float]]

Create a smooth transition between a camera view and a target view.

leggedsnake.world_visualizer.video(linkage: Any, duration: float = 30, save: bool = False, dynamic_camera: bool = True) None

Simulate a linkage with video output.

Parameters:
  • linkage (Walker, DynamicLinkage, or legacy Linkage) – The mechanism to simulate.

  • duration (float) – Duration in seconds.

  • save (bool) – Save as video (not yet implemented).

  • dynamic_camera (bool) – Follow the mechanism vs. wider view.

leggedsnake.world_visualizer.video_debug(linkage: Any) None

Launch the simulation frame by frame, useful for debug.