Skip navigation


warning: Creating default object from empty value in /var/www/vhosts/ on line 33.

Fishermen living around the port of El Callao, Peru have harvested the sea as a means of survival since the 16th century. Now, a global shipping industry giant based in the Netherlands is planning a project to modernize El Callao, Peru’s largest and oldest port. The project will expand port operations over the next couple [...]

Your rating: None

I have just released a new tutorial for Cinder. It is a 5 chapter addition to Hello, Cinder. It covers the creation of a flocking (or shoaling) system. I used the source code from this tutorial to make the following video.

The tutorial is based on the teachings of Craig Reynolds whose landmark 1987 paper on flocking behavior is still the foundation for most flocking simulations. It has also been influenced by the work of Iain Couzin of the Princeton Collective Animal Behavior lab. I particularly enjoy this short lecture he gave at the inaugural webcast of Awe-maggedon by RadioLab.

The flocking tutorial picks up where Hello, Cinder tour left off. In the first 5 chapters (section 1) of the tour, we create a 2D particle engine. The next 5 chapters (section 2) turn the particle engine into a 4 rule flocking system complete with predators.

Chapter 1 discusses the Cinder Camera class and explain how to create a 3D perspective camera. I also add a graphical interface that can be used to control parameters in real-time.

Chapter 2 introduces the first rule for our flocking simulation: Separation (repulsion). We show how to use a repulsive force to keep particles from getting too close to each other.

Chapter 3 explains the second rule: Cohesion (attraction). Now we show how to keep the particles from drifting too far away from each other.

Chapter 4 adds the third rule to the simulation: Alignment (orientation). The particles are now able to change their flight direction based on the flight direction of neighbors. The flocking behavior finally emerges.

Chapter 5, the final chapter, personalizes the rules and introduces a fourth rule: Evasion. Predators are added to the simulation. They chase after the particles by focusing on areas of high concentration. At the same time, Particles (prey) make every effort to flee from any nearby predators.

There is a source code Cinder project for each chapter so you can follow along with the tutorial. If you wish to dive right in and start playing with the flocking source, go straight to the Section 2: Chapter 5 source. It contains the same logic I used to make the Bait Ball video below:

The tutorial received much loving feedback and editing from Andrew Bell, Mike Creighton, and Noah King. Many thanks to them all. If you have any feedback, advice, or improvements, please contribute to the Cinder forum post, Flocking Tutorial.

You can download the source for the whole 10 chapters here or just grab it off the git repo.

Your rating: None