Flocking Simulations in C#

Flocking Simulations in C#

C# Coding for Grasshopper Course

What is the course about?

This course will focus on more intermediate coding techniques by providing an insight into Craig Reynold’s Boids flocking simulations. The course will apply concepts of object-oriented programming to behavioural algorithms to generate emergent forms and patterns.

We will examine how to create a basic agent system with our own Agent class in C# first, then apply optimization algorithms to speed up our code and increase the capacity of our algorithm to run larger quantities of data at once.

We will then learn how to add trail lines to our agents to create amazing flocking patterns, and add extra stigmergy behaviours to our agents.

What will you learn in each video?

In this tutorial we’re going to create an Agent class for our flocking simulation, and setup a reset toggle that resets and runs our agents on command. It is recommended you have watched our Introduction to C# for Grasshopper course prior to undertaking this tutorial. By the end of this tutorial we will have the foundations for our flocking simulation setup in C# and be ready to add behavioural algorithms.

In this tutorial we will continue our agent system in C# for Grasshopper and begin looking into Craig Reynolds boids behaviours and integrate a separation behaviour into our agent class. The separation behaviour works to prevent agent collisions and keep them nicely spaced apart from one another during our simulation.

In this tutorial we will continue our agent system in C# for Grasshopper and look at how to contain our agent simulation from the previous tutorial within any rectangular boundary we draw in Grasshopper.

In this tutorial we will continue our agent system in C# for Grasshopper and begin looking into Craig Reynolds cohesion behaviour from his boids simulations. The cohesion behaviour works to bring agents closer to one another. It is calculated by finding other agents in the current agent field of view, and then moving towards the average location of these agents.

In this tutorial we will continue our agent system in C# for Grasshopper and begin looking into applying Craig Reynolds final boids behaviour to our agent system: the alignment behaviour. The alignment behaviours works to essentially group flockmates or agents together and move cohesively in a similar direction. We will write this function by locating other agents in our field of view and add their speed vector to realign our own speed, and therefore agent direction.

In this tutorial we will examine a method called ‘Multithreading’ that will help speed up the computation of our C# code. We will examine this method as a series of examples in isolation first, and then apply it to our agent code

In this tutorial we will continue our agent system in C# for Grasshopper and write a new class to visualize polyline trails that follow our agents paths.

In this tutorial we will continue our agent system in C# for Grasshopper and create a C# component that turns our trails into a mesh geometry with a fading gradient colour.

In this tutorial we will continue our agent system in C# for Grasshopper and create some ‘stigmergy’ behaviours in our code. Stigmergy behaviours are born out of responses to the environment of the simulation. These could include things like a behaviour where agents have been running for a certain length of a simulation, response to trails in the environment or even responses to overly crowded areas in the simulation.

What are the learning objectives for the course?

Course image gallery:

Scroll to Top