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.
Group 1
and Group 2
agents. Agents from the second group are rendered as the larger dots.k
nearest neighbors outside of the zone of orientation for their attraction vector.[0, 180]
) where the agent can not adjust their direction vector greater than this number for an individual iterationPlay
button to start animationPause
button to stop animationNext
button to do one time step of the algorithm.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
Modified http://www.numericjs.com/lib/numeric-1.2.6.js to a secure url
https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
https://www.numericjs.com/lib/numeric-1.2.6.js
https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js
https://d3js.org/d3.v4.min.js