swarmsim.world.RectangularWorld#
2D world module.
The RectangularWorld is a 2D world.
It is currently the only world type available.
Config Class#
- class swarmsim.world.RectangularWorld.RectangularWorldConfig(*args, **kwargs)[source]#
Config dataclass for a RectangularWorld.
- Attributes:
- radius
- seed
- stop_at
Methods
as_dict
asdict
create_world
factor_zoom
from_dict
from_yaml
save_yaml
- background_color: tuple[int, int, int] = (0, 0, 0)[source]#
The background color of the world. Default is black.
- seed: int | None = None[source]#
The seed to use for the world. If None, the world will be seeded based on system time.
- Type:
int | None
- stop_at: int | Callable | None = None[source]#
The maximum number of steps to run the simulation.
- Type:
int | Callable | None
- time_step: float = 0.016666666666666666[source]#
\(\Delta t\) delta time (seconds)
The time step, or delta time, is used by simulated objects and agents when calculating anything that depends on time, such as velocity.
It is stored into the world’s
dt
attribute, which should be used if an agent needs to know “how much time passed in the simulated world since the last tick”.It does not directly determine how fast the simulation runs, or the FPS.
- Type:
World Class#
- class swarmsim.world.RectangularWorld.RectangularWorld(config: RectangularWorldConfig, initialize=True)[source]#
- Attributes:
- behavior_dict
- original_zoom
Methods
do_zoom
(point, v)zooms the camera around a point
draw
(screen[, offset])Cycle through the entire population and draw the agents and objects.
getNeighborsWithinDistance
(center, r[, excluded])Given the center of a circle, find all Agents located within the circumference defined by center and r
onClick
(event)Handle mouse click events.
onZoom
(mouse_event, scroll_event)Handle mouse wheel events.
on_mouse
(pos)Handle mouse movement events.
withinWorldBoundaries
(agent)Set agent position with respect to the world's boundaries and the bounding box of the agent
Reset the camera position and zoom level to the original zoom level.
as_config_dict
as_dict
asdict
attach_gui
collision_forward
evaluate
from_config
getAgentsMatchingYRange
getBehaviorVector
handleGoalCollisions
handleWallCollisions
handle_held_keys
handle_key_press
handle_middle_mouse_events
handle_middle_mouse_held
preventAgentCollisions
removeAgent
set_seed
setup
setup_objects
step
step_agents
step_metrics
step_objects
step_spawners
- draw(screen, offset=None)[source]#
Cycle through the entire population and draw the agents and objects.
- dt[source]#
\(\Delta t\) delta time (seconds)
The time step, or delta time, is used by simulated objects and agents when calculating anything that depends on time, such as velocity, or any time an agent needs to know “how much time passed in the simulated world since the last tick”.
It does not directly determine how fast the simulation runs, or the FPS.
- Type:
- getNeighborsWithinDistance(center: None, r, excluded=None) list [source]#
Given the center of a circle, find all Agents located within the circumference defined by center and r
Module Attributes
|
words to put in SVG layer names to indicate if that object should collide |
|
Functions
|
Get collision config dict from string or bool. |
Classes
|
|
|
Config dataclass for a RectangularWorld. |