// Flocking // Daniel Shiffman // The Nature of Code, Spring 2009 // Demonstration of Craig Reynolds' "Flocking" behavior // See: http://www.red3d.com/cwr/ // Rules: Cohesion, Separation, Alignment // Click mouse to add boids into the system Flock flock; void setup() { size(600,200); flock = new Flock(); // Add an initial set of boids into the system for (int i = 0; i < 100; i++) { flock.addBoid(new Boid(new PVector(width/2,height/2),3.0,0.05)); } smooth(); } void draw() { background(255); flock.run(); } // Add a new boid into the System void mousePressed() { flock.addBoid(new Boid(new PVector(mouseX,mouseY),2.0,0.05f)); }