changes to simulate examples

This commit is contained in:
shiffman
2011-12-15 17:27:25 +00:00
parent 2072bceb6e
commit 65f795f70d
12 changed files with 205 additions and 307 deletions

View File

@@ -3,12 +3,12 @@
class ParticleSystem {
ArrayList particles; // An arraylist for all the particles
ArrayList<Particle> 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
particles = new ArrayList<Particle>(); // Initialize the arraylist
origin = v.get(); // Store the origin point
img = img_;
for (int i = 0; i < num; i++) {
@@ -17,21 +17,21 @@ class ParticleSystem {
}
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);
Iterator<Particle> it = particles.iterator();
while (it.hasNext()) {
Particle p = it.next();
p.run();
if (p.dead()) {
particles.remove(i);
it.remove();
}
}
}
// 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 applyForce(PVector dir) {
// Enhanced loop!!!
for (Particle p: particles) {
p.applyForce(dir);
}
}
@@ -55,3 +55,4 @@ class ParticleSystem {
}