Re-adding Topics to SVN

This commit is contained in:
Casey Reas
2011-09-05 23:58:47 +00:00
parent 4fc6dcca86
commit 391c79c2b6
219 changed files with 31093 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// A class to describe a group of Particles
// An ArrayList is used to manage the list of Particles
class ParticleSystem {
ArrayList particles; // An arraylist for all the particles
PVector origin; // An origin point for where particles are birthed
PImage img;
ParticleSystem(int num, PVector v, PImage img_) {
particles = new ArrayList(); // Initialize the arraylist
origin = v.get(); // Store the origin point
img = img_;
for (int i = 0; i < num; i++) {
particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist
}
}
void run() {
// Cycle through the ArrayList backwards b/c we are deleting
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = (Particle) particles.get(i);
p.run();
if (p.dead()) {
particles.remove(i);
}
}
}
// Method to add a force vector to all particles currently in the system
void add_force(PVector dir) {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = (Particle) particles.get(i);
p.add_force(dir);
}
}
void addParticle() {
particles.add(new Particle(origin,img));
}
void addParticle(Particle p) {
particles.add(p);
}
// A method to test if the particle system still has particles
boolean dead() {
if (particles.isEmpty()) {
return true;
} else {
return false;
}
}
}