/* * This class provides interpolation between points for smooth animations. * * Based on code from Ben Fry's Processing book. * * Modified by Pehr to make most of the parameters private to discourage accidentally meddling with it */ public class Integrator { final float DAMPING = 0.5f; final float ATTRACTION = 0.2f; private float value; private float vel; private float accel; private float force; private float mass = 1; float damping = DAMPING; float attraction = ATTRACTION; boolean targeting; private float target; Integrator() { } Integrator(float value) { this.value = value; } Integrator(float value, float damping, float attraction) { this.value = value; this.damping = damping; this.attraction = attraction; } void set(float v) { value = v; } void update() { if (targeting) { force += attraction * (target - value); } accel = force / mass; vel = (vel + accel) * damping; value += vel; force = 0; } void target(float t) { targeting = true; target = t; } float value(){ return value; } void noTarget() { targeting = false; } float velocty(){return vel;} float acceleration(){return accel;} boolean moving(){ return Math.abs(vel)>0.001; //return true; } }