-
Notifications
You must be signed in to change notification settings - Fork 0
Okerew edited this page Sep 13, 2025
·
1 revision
The VisualizerWrapper class provides a wrapper for visualizing an Environment object using a visualizer. It manages the lifecycle of the visualizer, updates cell positions, and handles cell movement within the environment.
class VisualizerWrapper:
def __init__(self, environment: Environment):
"""
Initialize a new VisualizerWrapper object.
:param environment: Environment object to visualize
"""
...| Attribute | Type | Description |
|---|---|---|
environment |
Environment |
The environment object to visualize. |
vis |
visualizer.Visualizer |
The visualizer instance for rendering the environment. |
running |
bool |
Flag indicating whether the visualizer is running. |
-
__init__(self, environment: Environment)Initializes a newVisualizerWrapperinstance with the specified environment. It sets up the visualizer with dimensions based on the environment's width and height.
-
start(self)Starts the visualizer and begins the visualization loop. -
stop(self)Stops the visualizer and returns the current cell positions. -
run_visualizer(self)Runs the visualizer loop, updating cell positions and rendering the environment.-
Details:
- Continuously updates the visualizer with the latest cell positions from the environment.
- Runs until
self.runningis set toFalse. - Updates every 100 milliseconds.
-
Details:
-
move_cell(self, cell_id: int, new_x: int, new_y: int)Moves a cell within the environment to a new position.-
Parameters:
-
cell_id: The ID of the cell to move. -
new_x: The new x-coordinate for the cell. -
new_y: The new y-coordinate for the cell.
-
-
Parameters:
# Create an environment
environment = Environment(
name="Forest",
width=50,
height=50,
temperature=25.0,
humidity=50.0,
env_type="normal"
)
# Add some cells to the environment
cell1 = Cell(name="Cell1", cell_type="epithelial")
cell2 = Cell(name="Cell2", cell_type="neuron")
environment.add_cell(cell1, (10, 10))
environment.add_cell(cell2, (20, 20))
# Create a VisualizerWrapper
visualizer_wrapper = VisualizerWrapper(environment)
# Start the visualizer
visualizer_wrapper.start()
# Let the visualizer run for a while (e.g., 5 seconds)
time.sleep(5)
# Stop the visualizer and get cell positions
cell_positions = visualizer_wrapper.stop()
print("Cell positions after visualization:", cell_positions)Cell positions after visualization: [
{'x': 10, 'y': 10, 'health': 100, 'type': 'Cell', 'id': <cell_id_1>},
{'x': 20, 'y': 20, 'health': 100, 'type': 'Cell', 'id': <cell_id_2>}
]
-
time: For managing the timing of visualizer updates. -
biobridge.enviromental.visualizer: Module providing theVisualizerclass for rendering the environment. -
Environment: Class representing the biological environment to visualize.
- The
run_visualizermethod checks the return value ofvis.run_once()to determine if the visualizer should continue running. - The
move_cellmethod delegates cell movement to the environment, which handles boundary checks and position validation.
- The
VisualizerWrapperclass is designed to work with theEnvironmentclass and a visualizer module. - The visualizer updates at a fixed interval (100ms) to provide a smooth visualization experience.
- The
move_cellmethod is set as a callback for the visualizer to handle cell movement events.