larvaworld.lib.screen.rendering =============================== .. py:module:: larvaworld.lib.screen.rendering .. autoapi-nested-parse:: Screen renderable items for pygame-based simulation visualization Classes ------- .. autoapisummary:: larvaworld.lib.screen.rendering.ScreenTextBoxRect larvaworld.lib.screen.rendering.ScreenTextBox larvaworld.lib.screen.rendering.IDBox larvaworld.lib.screen.rendering.ScreenMsgText larvaworld.lib.screen.rendering.SimulationClock larvaworld.lib.screen.rendering.SimulationScale larvaworld.lib.screen.rendering.SimulationState Module Contents --------------- .. py:class:: ScreenTextBoxRect(**kwargs: Any) Bases: :py:obj:`ScreenTextFont`, :py:obj:`larvaworld.lib.param.Viewable` Text 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) .. py:attribute:: visible .. py:attribute:: frame_rect .. py:attribute:: linewidth .. py:attribute:: show_frame .. py:attribute:: text_centre .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:class:: ScreenTextBox(**kwargs: Any) Bases: :py:obj:`ScreenTextFont`, :py:obj:`larvaworld.lib.param.ViewableToggleable`, :py:obj:`larvaworld.lib.param.Area2DPixel` Toggle-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 .. py:attribute:: dims .. py:attribute:: visible .. py:attribute:: linewidth .. py:attribute:: show_frame .. py:attribute:: frame_rect :value: None .. py:method:: set_frame_rect(pos: Any | None = None, **kwargs: Any) .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:class:: IDBox(**kwargs: Any) Bases: :py:obj:`ScreenTextFont`, :py:obj:`larvaworld.lib.param.ViewableToggleable` Text 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 .. py:attribute:: visible .. py:attribute:: agent .. py:method:: update_agent() -> None .. py:method:: update_font_centre_pos(v: Any) -> None .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:class:: ScreenMsgText(reference_area: Any, **kwargs: Any) Bases: :py:obj:`ScreenTextFontRel`, :py:obj:`larvaworld.lib.param.Viewable` Message 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) .. py:attribute:: text_centre_scale .. py:attribute:: font_size_scale .. py:attribute:: font_type .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:method:: set_default_color(color: Any) -> None .. py:class:: SimulationClock(sim_step_in_sec: float, **kwargs: Any) Bases: :py:obj:`PosPixelRel2AreaViewable` Clock 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 .. py:attribute:: pos_scale .. py:attribute:: sim_step_in_dms .. py:attribute:: time_in_min :value: 0 .. py:attribute:: dmsecond :value: 0 .. py:attribute:: second :value: 0 .. py:attribute:: minute :value: 0 .. py:attribute:: hour :value: 0 .. py:attribute:: text_fonts .. py:method:: tick_clock() -> None .. py:method:: reset() -> None Reset the clock to zero. .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:method:: set_default_color(color: Any) -> None .. py:class:: SimulationScale(**kwargs: Any) Bases: :py:obj:`PosPixelRel2AreaViewable` Scale 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 .. py:attribute:: pos_scale .. py:attribute:: text_font .. py:attribute:: lines :value: None .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:method:: set_default_color(color: Any) -> None .. py:class:: SimulationState(model: Any, **kwargs: Any) Bases: :py:obj:`PosPixelRel2AreaViewable` Simulation 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) .. py:attribute:: pos_scale .. py:attribute:: model .. py:attribute:: text_font .. py:method:: set_text(text: str) -> None .. py:method:: draw(v: Any, **kwargs: Any) -> None .. py:method:: set_default_color(color: Any) -> None