// A particle moved by Verlet Integration - that means velocity is inferred from it's previous and current position class Particle extends Point{ float px, py, tempX, tempY, ix, iy; // Constructor Particle(float x, float y){ super(x, y); px = tempX = ix = x; py = tempY = iy = y; } // Movement is executed by this method void verletSpecific(float gravityX, float gravityY, float damping){ tempX = x; tempY = y; x += damping * (x - px) + gravityX; y += damping * (y - py) + gravityY; px = tempX; py = tempY; } // Fix the particle to a given point and kill it's velocity void setPosition(float x, float y){ this.x = px = tempX = ix = x; this.y = py = tempY = iy = y; } // Fix the particle to it's initialisation point void pin(){ x = px = tempX = ix; y = py = tempY = iy; } // Get the distance moved in the last frame float speed(){ return sqrt((x-px)*(x-px)+(y-py)*(y-py)); } // Add speed to the particle by displacing it's last location void addVelocity(float x, float y){ px -= x; py -= y; } // Provide a copy of the particle with matching current behaviour and add it to the physics system Particle copy(){ Particle temp = new Particle(x, y); temp.px = px; temp.py = py; temp.ix = ix; temp.iy = iy; return temp; } }