// Simple Particle System // Daniel Shiffman // A class to describe a group of Particles // An ArrayList is used to manage the list of Particles class BoidSystem { ArrayList boids; // An arraylist for all the particles Vector3D origin; // An origin point for where particles are birthed BoidSystem(int num, Vector3D v) { boids = new ArrayList(); // Initialize the arraylist origin = v.copy(); // Store the origin point // Add an initial group of particles to the ArrayList for (int i = 0; i < num; i++) { if (random(1) > 0.5) { boids.add(new Female(new Vector3D(width - width/4,height - height/4),2.0f,0.05f,random(10,15))); } else { // There is a 50% chance we will add a "crazy particle" into the system boids.add(new Male(new Vector3D(width/4,height/4),2.0f,0.05f,random(10,15))); } } } void run() { for (int i = 0; i < boids.size(); i++) { Boid b = (Boid) boids.get(i); b.run(boids); // Passing the entire list of boids to each boid individually } } }