/** * Flocking * by Daniel Shiffman. * * An implementation of Craig Reynold's Boids program to simulate * the flocking behavior of birds. Each boid steers itself based on * rules of avoidance, alignment, and coherence. * * Click the mouse to add a new boid. */ Flock flock; PVector target; boolean seeking=false; int INITIAL_COUNT=50; void setup() { //size(640, 360); size(1280, 720); flock = new Flock(); // Add an initial set of boids into the system for (int i = 0; i < INITIAL_COUNT; i++) { flock.addBoid(new Boid(width/2,height/2)); } target = new PVector(); } void draw() { background(50); flock.run(); if(seeking) { flock.seek(target); line(target.x-10, target.y, target.x+10, target.y); line(target.x, target.y-10, target.x, target.y+10); } } // Add a new boid into the System void mousePressed() { //flock.addBoid(new Boid(mouseX,mouseY)); seeking=true; target.x=mouseX; target.y=mouseY; //flock.seek(target); }