Files
processing4/java/examples/Books/Visualizing Data/ch03-usmap/step15_framerate/Integrator.pde
2011-01-26 19:35:23 +00:00

61 lines
852 B
Plaintext

class Integrator {
final float DAMPING = 0.5f;
final float ATTRACTION = 0.2f;
float value;
float vel;
float accel;
float force;
float mass = 1;
float damping = DAMPING;
float attraction = ATTRACTION;
boolean targeting;
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;
}
void noTarget() {
targeting = false;
}
}