ArrayList particles; PVector dissipativeForce = new PVector(); void setup() { size(400, 400); stroke(0); strokeWeight(3); fill(150); smooth(); particles = new ArrayList(); } void draw() { background(255); //only create when mouse moves if (abs(mouseX-pmouseX) > 0.0001) { particles.add(new Particle()); } for (int i = particles.size()-1; i >= 0; i--) { Particle p = (Particle)particles.get(i); // experiment w/ different friction coefficients applyDissipativeForce(p, 0.08); if(!p.exist()) { particles.remove(i); } } } void applyDissipativeForce(Particle p, float friction) { PVector f = PVector.mult(p.velocity, -friction); p.applyForce(f); } public class Particle { PVector location; PVector velocity; PVector acceleration; float mass; public Particle() { location = new PVector(mouseX, mouseY); //get velocity from direction and speed of mouse movement velocity = new PVector(mouseX-pmouseX, mouseY-pmouseY); acceleration = new PVector(0, 0, 0); mass = 1; } public boolean exist() { //when it comes to a rest, get rid of it if (abs(velocity.x) < 0.001 && abs(velocity.y) < 0.001) { return false; } velocity.add(acceleration); location.add(velocity); ellipse(location.x, location.y, 10, 10); acceleration.mult(0); return true; } void applyForce(PVector force) { acceleration.add(PVector.div(force, mass)); } }