class Particle { float[] distances = new float[particles.length]; PVector location = new PVector(0,0,0); PVector velocity = new PVector(0,0,0); PVector acceleration = new PVector(0,0,0); color pcolor; float total; float avg; float radius = 20; Particle(float _x, float _y, float _z) { location.x = _x; location.y = _y; location.z = _z; velocity = new PVector(random(-2,2),random(-2,2),random(-2,2)); } void update() { float d = location.dist(center); if (d > 400) { acceleration = PVector.sub(center, location); // acceleration.add(PVector.random3D()); acceleration.normalize(); acceleration.mult(0.2); velocity.normalize(); velocity.mult(.1); } location.add(velocity); velocity.add(acceleration); // velocity.mult(friction); // acceleration.mult(friction); } void show() { total = 0; avg = 0; for (int i = 0; i < particles.length; i++) { distances[i] = particles[i].location.dist(location); for( int j = 0; j < distances.length; j++ ) { total += distances[j]; } avg = total / distances.length; println(avg); if (avg > 1000) { pcolor = color(255,0,0); } else pcolor = color(255); } pushMatrix(); translate(location.x, location.y, location.z); fill(pcolor); noStroke(); sphere(radius); popMatrix(); } }