This example is an implementation of a simple flocking algorithm that uses the dynamics of repulsion, attraction, and orientation zones. This example is based off of the algorithm described by Couzin.
The basic principle is that each agent has three regions in a growing radius around it: a zone of repulsion, a zone of orientation, and a zone of attraction respectively. By editing the sizes of these zones you can expect to experience different behaviour.
This example allows you to see the behavior when two types of agents are used, allowing you to specify parameters for each group.
There are two basic types of parameters used: initial conditions and agent parameters. Agent parameters can be updated any time, including while in play. Initial conditions however require a reset before they take effect.
Note: If an initial condition is changed then the
Reset button will turn yellow, indicating that a reset is required before some changes take effect.
- Agents: The number of agents to simulate
- Sparsity: The spacing between agents at start, where higher numbers correspond to the agents being spaced further apart.
- Distribution: The distribution between
Group 1 and
Group 2 agents. Agents from the second group are rendered as the larger dots.
- Metric: The metric type used for the respective group for their zones of attraction. The two options are:
- distance: The agent uses a zone of attraction, specified by the radius
- knn: The agent uses the
k nearest neighbors outside of the zone of orientation for their attraction vector.
- Zr: The radius of the zone of repulsion
- Zo: The radius of the zone of orientation
- Za: The radius of the zone of attraction (distance metric only)
- k: The number of neighbors outside of the zone of orientation to use for the attraction vector (knn metric only)
- s: The speed, or the distance per iteration an individual agent travels
- θ: The turn rate (between
[0, 180]) where the agent can not adjust their direction vector greater than this number for an individual iteration
- Black: point is not being influenced by any other points (no points in any zones)
- Red: point is being repulsed (contains points in its zone of repulsion)
- Blue: point is being influenced by attraction forces only (contains points only in its zone of attraction)
- Lawn Green: point is being influenced by orientation forces only (contains points only in its zone of orientation)
- Turquoise: point is being influenced by both attraction and orientation forces (cointains points in both its zone of attraction and zone of orientation)
- Use the
Play button to start animation
- Use the
Pause button to stop animation
- Use the
Next button to do one time step of the algorithm.
- Clicking a point toggles display of its zone radii.
- While paused, points can also be dragged around and positioned.
Dragging/Zooming behavior forked from mbostock's block: Drag & Zoom II
forked from lwthatcher's block: Directional Forces
forked from lwthatcher's block: Flocking
forked from lwthatcher's block: Flocking II
forked from lwthatcher's block: Flocking III
forked from lwthatcher's block: Flocking IV