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

agents: list[source]#

The list of agent configs for the world

Type:

list

as_dict()[source]#
asdict()[source]#
background_color: tuple[int, int, int] = (0, 0, 0)[source]#

The background color of the world. Default is black.

Type:

tuple[int, int, int]

collide_walls: bool = True[source]#

Currently unused.

create_world()[source]#
detectable_walls: bool = False[source]#

Currently unused.

factor_zoom(zoom)[source]#
flags: dict[str, int][source]#
classmethod from_dict(env)[source]#
classmethod from_yaml(path)[source]#
goals: list[source]#
metadata: dict[source]#
metrics: list[source]#

The list of metrics configs for the world

Type:

list

objects: list[source]#

The list of objects configs for the world

Type:

list

property radius[source]#
save_yaml(path)[source]#
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

show_walls: bool = True[source]#

Currently unused.

size: None = (5, 5)[source]#

size of the world.

spawners: list[source]#

The list of spawner configs for the world

Type:

list

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:

float

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

zoom_reset()

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

as_config_dict()[source]#
property behavior_dict[source]#
collision_forward(agent, colliding_agent)[source]#
do_zoom(point: ndarray[2, dtype[int]], v: int | float)[source]#

zooms the camera around a point

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:

float

getAgentsMatchingYRange(bb: AABB)[source]#
getBehaviorVector()[source]#
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

handleGoalCollisions(agent)[source]#
handleWallCollisions(agent: None)[source]#
handle_held_keys(keys)[source]#
handle_key_press(event)[source]#
handle_middle_mouse_events(events)[source]#
handle_middle_mouse_held(pos)[source]#
mouse_position[source]#

last mouse position in viewport pixel coordinates (UL 0,0).

Type:

np.ndarray[int, int]

onClick(event) None[source]#

Handle mouse click events.

onZoom(mouse_event, scroll_event)[source]#

Handle mouse wheel events.

on_mouse(pos)[source]#

Handle mouse movement events.

property original_zoom[source]#
pos[source]#

current offset of the camera when draw()\ ing.

Type:

np.ndarray[float, float]

preventAgentCollisions(agent: None, forward_freeze=False) None[source]#
removeAgent(agent)[source]#
selected[source]#

currently selected agent.

Type:

Agent

setup_objects(objects)[source]#
step_agents()[source]#
withinWorldBoundaries(agent: None)[source]#

Set agent position with respect to the world’s boundaries and the bounding box of the agent

zoom[source]#

current zoom level used when draw()\ ing.

Type:

float

zoom_reset()[source]#

Reset the camera position and zoom level to the original zoom level.

Module Attributes

COLLISION_CLASSES

words to put in SVG layer names to indicate if that object should collide

remove_special_classes(names, *[, classes])

Functions

get_collision_config(collides)

Get collision config dict from string or bool.

Classes

RectangularWorld(config[, initialize])

RectangularWorldConfig(*args, **kwargs)

Config dataclass for a RectangularWorld.