larvaworld.lib.screen.rendering
Screen renderable items for pygame-based simulation visualization
Classes
Text box with rectangular frame at fixed screen position. |
|
Toggle-able text box with frame at pixel coordinates. |
|
Text box displaying agent ID that follows the agent. |
|
Message text display with relative positioning. |
|
Clock display for simulation time tracking. |
|
Scale bar display for spatial reference. |
|
Simulation state display for runtime information. |
Module Contents
- class larvaworld.lib.screen.rendering.ScreenTextBoxRect(**kwargs: Any)
Bases:
ScreenTextFont,larvaworld.lib.param.ViewableText box with rectangular frame at fixed screen position.
Displays text within a rectangular frame, commonly used for labels and status indicators in pygame visualizations.
- Attributes:
visible: Whether the text box is visible frame_rect: The rectangular frame object linewidth: Width of the frame border show_frame: Whether to draw the rectangular frame
- Example:
>>> text_box = ScreenTextBoxRect(text="Status", frame_rect=rect) >>> text_box.draw(viewer)
- visible
- frame_rect
- linewidth
- show_frame
- text_centre
- draw(v: Any, **kwargs: Any) None
- class larvaworld.lib.screen.rendering.ScreenTextBox(**kwargs: Any)
Bases:
ScreenTextFont,larvaworld.lib.param.ViewableToggleable,larvaworld.lib.param.Area2DPixelToggle-able text box with frame at pixel coordinates.
Displays text within a rectangular area that can be toggled on/off, with optional frame rendering for UI elements.
- Attributes:
dims: Dimensions as (width, height) pixel tuple visible: Whether the text box is visible linewidth: Width of the frame border show_frame: Whether to draw the rectangular frame
- Example:
>>> text_box = ScreenTextBox(text="Info", dims=(200, 40)) >>> text_box.toggle() # Show/hide
- dims
- visible
- linewidth
- show_frame
- frame_rect = None
- set_frame_rect(pos: Any | None = None, **kwargs: Any)
- draw(v: Any, **kwargs: Any) None
- class larvaworld.lib.screen.rendering.IDBox(**kwargs: Any)
Bases:
ScreenTextFont,larvaworld.lib.param.ViewableToggleableText box displaying agent ID that follows the agent.
Renders agent unique ID as text near the agent position, using the agent’s color for visibility during visualization.
- Attributes:
visible: Whether the ID box is visible agent: The agent whose ID is displayed
- Example:
>>> id_box = IDBox(agent=larva_agent) >>> id_box.draw(viewer) # Draws ID text near agent
- visible
- agent
- update_agent() None
- update_font_centre_pos(v: Any) None
- draw(v: Any, **kwargs: Any) None
- class larvaworld.lib.screen.rendering.ScreenMsgText(reference_area: Any, **kwargs: Any)
Bases:
ScreenTextFontRel,larvaworld.lib.param.ViewableMessage text display with relative positioning.
Displays temporary or persistent messages at screen positions relative to a reference area, used for notifications and alerts.
- Attributes:
text_centre_scale: Text center position relative to reference font_size_scale: Font size relative to window size font_type: Font type for rendering
- Example:
>>> msg = ScreenMsgText(reference_area=screen_area, text="Paused") >>> msg.draw(viewer)
- text_centre_scale
- font_size_scale
- font_type
- draw(v: Any, **kwargs: Any) None
- set_default_color(color: Any) None
- class larvaworld.lib.screen.rendering.SimulationClock(sim_step_in_sec: float, **kwargs: Any)
Bases:
PosPixelRel2AreaViewableClock display for simulation time tracking.
Renders current simulation time in HH:MM:SS:ds format (hours:minutes:seconds:deciseconds) at a fixed screen position during visualization.
- Attributes:
pos_scale: Position scale relative to screen area sim_step_in_dms: Simulation step size in deciseconds hour, minute, second, dmsecond: Current time components text_fonts: Dictionary of font objects for each time component
- Example:
>>> clock = SimulationClock(sim_step_in_sec=0.1, reference_area=screen) >>> clock.tick_clock() # Advance by one time step >>> clock.draw(viewer) # Render current time
- pos_scale
- sim_step_in_dms
- time_in_min = 0
- dmsecond = 0
- second = 0
- minute = 0
- hour = 0
- text_fonts
- tick_clock() None
- reset() None
Reset the clock to zero.
- draw(v: Any, **kwargs: Any) None
- set_default_color(color: Any) None
- class larvaworld.lib.screen.rendering.SimulationScale(**kwargs: Any)
Bases:
PosPixelRel2AreaViewableScale bar display for spatial reference.
Renders a scale bar indicating spatial dimensions in millimeters, helping interpret distances in the visualization.
- Attributes:
pos_scale: Position scale relative to screen area text_font: Font object for scale label lines: Line segments forming the scale bar
- Example:
>>> scale = SimulationScale(reference_area=screen) >>> scale.draw(viewer) # Draws scale bar with mm label
- pos_scale
- text_font
- lines = None
- draw(v: Any, **kwargs: Any) None
- set_default_color(color: Any) None
- class larvaworld.lib.screen.rendering.SimulationState(model: Any, **kwargs: Any)
Bases:
PosPixelRel2AreaViewableSimulation state display for runtime information.
Renders current simulation state (running, paused, etc.) and other status information during visualization.
- Attributes:
pos_scale: Position scale relative to screen area model: Reference to the simulation model text_font: Font object for state text
- Example:
>>> state = SimulationState(model=sim_model, reference_area=screen) >>> state.set_text("PAUSED") >>> state.draw(viewer)
- pos_scale
- model
- text_font
- set_text(text: str) None
- draw(v: Any, **kwargs: Any) None
- set_default_color(color: Any) None