Deprecating Random.nextGaussian() in lieu of randomGaussian.

This change brings the Android example in-line with the Java
example.
References processing/processing_web#45
This commit is contained in:
Yong Bakos
2013-04-05 12:10:50 -06:00
parent ae312eee2d
commit d1e3a60d5e
3 changed files with 66 additions and 110 deletions

View File

@@ -1,57 +1,42 @@
// A class to describe a group of Particles
// An ArrayList is used to manage the list 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
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
origin = v.get(); // Store the origin point
particles = new ArrayList<Particle>(); // 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
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);
Particle p = particles.get(i);
p.run();
if (p.dead()) {
if (p.isDead()) {
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 applyForce(PVector dir) {
// Enhanced loop!!!
for (Particle p : particles) {
p.applyForce(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;
}
}
}