package whiteout;
import javafx.animation.SimpleInterpolator;
import java.lang.Math;
/* This is the actual interpolator class which implements
* the standard spring equation.
* It can be configured using the public-init vars
* at the top, but reasonable defaults are provided.
* */
public class SpringInterpolator extends SimpleInterpolator {
// the amplitude of the wave
// controls how far out the object can go from it's final stopping point.
public-init var amplitude:Number = 1.0;
// determines the weight of the object
// makes the wave motion go longer and farther
public-init var mass:Number = 0.058;
// the stiffness of the wave motion / spring
// makes the motion shorter and more snappy
public-init var stiffness:Number = 12.0;
// makes the wave motion be out of phase, so that the object
// doesn't end up on the final resting spot.
// this variable is usually never changed
public-init var phase:Number = 0.0;
// if this should do a normal spring or a bounce motion
public-init var bounce:Boolean = false;
def pulsation = Math.sqrt(stiffness / mass);
// the actual spring equation
override public function curve(t: Number) : Number {
def t2 = -Math.cos(pulsation * t + phase+Math.PI) * (1 - t) * amplitude ;
// use the absolute value of the distance from the end point
// if doing a bounce
if (bounce) 1 - Math.abs(t2) else 1 - t2;
}
}