Viewer

The Viewer is a simple way to visualize your simulations. After creating the Viewer, just call draw() each step (or less frequently) to see the current state of the World.

Note

The maximum Viewer refresh rate (set at creation with the display_rate argument) also limits the simulation rate. If you want to run faster/higher-throughput simulations, don’t use the Viewer, or make it draw less frequently than every tick.

class gridsim.viewer.Viewer(world: gridsim.world.World, window_width: int = 1080, display_rate: int = 10, show_grid: bool = False, show_network: bool = False, show_time: bool = False)

Viewer to display the simulation of a World.

This is optional (for debugging and visualization); simulations can be run much faster if the Viewer is not used.

Parameters
  • world (World) – World to display

  • window_width (int, optional) – Width (in pixels) of the window to display the World, by default 1080

  • display_rate (int, optional) – How fast to update the view (ticks/s), by default 10. In each tick, robots will move by one cell, so keep this low to be able to interpret what’s going on.

  • show_grid (bool, optional) – Whether to show the underlying grid in the World, by default False.

  • show_network (bool, optional) – Whether to visualize the current communication network of the robots, by default False. Communication connections between robots are shown as lines between robots.

  • show_time (bool, optional) – Whether to draw the time (ticks) as text within the viewer window, by default False. (It is placed in the upper right corner.)

draw()

Draw all of the robots in the World into the World and its environment.

This will also draw the World’s environment (if one is set) and any tagged cells in the World.