// The Nature of Code // Daniel Shiffman // http://natureofcode.com class ParticleSystem { ArrayList particles; PVector origin; ParticleSystem(PVector location) { origin = location.get(); particles = new ArrayList(); } void addParticle() { float r = random(1); if (r < 0.5) { particles.add(new Particle(origin)); } else { particles.add(new ParticleChild(origin)); } } void run() { Iterator it = particles.iterator(); while (it.hasNext()) { Particle p = it.next(); p.run(); if (p.isDead()) { it.remove(); } } } }