The first example implements the most basic Boids (without advanced points). The code is easier to read and is enclosed by "Begin Simple Example Solution" and "End Simple Example Solution" comments.

The next example implements the following features:

  1. Objects bounce when they collide.
  2. Add obstacles to the scene.
  3. Implement “alignment” steering.
  4. Implement “separation” steering.
  5. Implement “cohesion” steering.
  6. Mouse attraction - have boids turn towards the mouse.

The code is enclosed by "Begin Bonus Example Solution" and "End Bonus Example Solution" comments.

This slider controls the maximum angle the Boids can turn (in radian):
Maximum angle:
This slider contros the maximum radius the Boids can "see" (in px) and determines which Boids count as "nearby neighbors":
Maximum radius:
These buttons provide example configurations of the weights below:

These sliders control the amount of steering due to alignment, separation, cohesion and mouse click (and hold):
Alignment weight:
Separation weight:
Cohesion weight:
Chasing weight:
Mouse weight:

Another example solution from 2023




speed

alignment

cohesion

separation


seconds.