Skip to main content
100%

Flocking

✓ Published0🌍 Public
TThanaporn-sk
Last edited Nov 1, 2019
Created on Nov 1, 2019

This interactive visualization demonstrates a flocking simulation where 30 agents move according to repulsion, orientation, and attraction zones, with colors indicating the current influence (red for repulsion, blue for attraction-only, green for orientation-only, turquoise for both). Users can adjust the three zone radii via number inputs, play, pause, or step through time using d3.interval, and click or drag points to inspect their radii and direction lines. The code uses d3.v4 with SVG rendering, d3.zoom for panning, and d3.transition for smooth radius changes.

AI-generated description

Flocking

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.

Color Key:

  • 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)

Controls:

  • 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 and direction line.
  • While paused, points can also be dragged around and positioned.

Dragging/Zooming behavior forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/3127661b6f13f9316be745e77fdfb084'>Drag & Zoom II</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/0414d5891a2ff084d48c1619e9a26d1c'>Directional Forces</a>

forked from <a href='http://bl.ocks.org/lwthatcher/'>lwthatcher</a>'s block: <a href='http://bl.ocks.org/lwthatcher/f03996c7a5efcde54b9bb6928a4ed901'>Flocking</a>

gpl-3.0 Licensed

Similar vizzes