floxs.predator_prey.viewer.PredatorPreyViewer¶
- class floxs.predator_prey.viewer.PredatorPreyViewer(name: str = 'predator_prey', env_size: Tuple[float, float] = (1.0, 1.0), prey_color: str = '#5ec962', predator_color: str = '#440154', render_mode: str = 'human')¶
Bases:
jumanji.viewer.MatplotlibViewer
[floxs.predator_prey.types.State
]Predator-prey environment visualiser
- Parameters:
name – Plot name, default
predator_prey
env_size – Tuple containing the dimensions of the environment
prey_color – Color applied to prey agents
predator_color – Color applied to predator agents
render_mode – Default
human
- animate(states: Sequence[floxs.predator_prey.types.State], interval: int, save_path: str | None = None) matplotlib.animation.FuncAnimation ¶
Create an animation from a sequence of states.
- Parameters:
states – Sequence of
State
objects corresponding to subsequent timesteps.interval – Delay between frames in milliseconds, default to 200.
save_path – The path where the animation file should be saved. If it is None, the plot will not be saved
- Returns:
Animation object that can be saved as a GIF, MP4, or rendered with HTML
- Return type:
FuncAnimation
- render(state: floxs.predator_prey.types.State, save_path: str | None = None) numpy.typing.NDArray | None ¶
Render a frame of the environment for a given state using matplotlib.
- Parameters:
state – State object containing the current dynamics of the environment.
save_path – Optional path to save the rendered environment image to.
- Returns:
RGB array if the render_mode is ‘rgb_array’.
- Return type:
Array