We’ve implemented a number of interesting interpolation functions in JavaFX this week using a simple Interpolator.fx class. An interpolator, which is used behind the scenes to calculate the changes between keyframes of an animation, can be set for any change using the Animation Inspector.

We’ve included some fun ones in the base class, including EaseIn, EaseOut, Bounce, SingleStep, and various others. You can, of course, provide your own subclasses.
Here’s an applet that shows off the standard interpolations, as well as a custom subclass.

The standard interpolators can be chosen from the drop-down menu. I’ve implemented a custom Perlin Noise interpolator for this example, that can add a little bit of random noise to any other interpolator. This can be used to make some movements more natural, since nothing in the world moves smoothly.
Another interpolator subclass we created was one that knows about colors. The color interpolator is based on any other interpolator, so you can animate from Red to Black using EaseIn, EaseBoth, Bounce, etc. If you change the color of a shape between keyframes, JFXBuilder automatically selects the Color interpolator for you.
The JavaFX Color object already has a method to interpolate between two colors, so our ColorInterpolator subclass becomes as simple as:
function ColorInterpolator.getValue(time:Number, start, end) { var ratio = parent.getValue(time,0,1); return ((Color)start).interpolate(end, ratio); }
This does an interpolation through RGB colorspace, but you could certainly imagine others. For the moment, that’s left as an exercise to the reader.
We’ll drop in more as we think of interesting ones. I’m currently thinking a Damped Harmonic Oscillator would be fun…