mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
61 lines
852 B
Plaintext
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;
|
|
}
|
|
}
|