Java Reference
In-Depth Information
def circ = Circle { centerX: 25 centerY: 100 radius: 25 };
var t = Timeline {
autoReverse:true
repeatCount:Timeline.INDEFINITE
keyFrames: [
at(2s) {
circ.centerX => 375
tween MagneticInterpolator {attraction:0.07}
}
]
};
The next figure depicts how the circle's centerX property is interpolated using the
MagneticInterpolator class.
How it works...
Given a start and an end value, interpolation provides the ability to algorithmically deduce an
in-between target value given ratio t where 0.0 <= t <= 1.0 . For instance when t = 1.0 ,
most interpolators will return the end value. In JavaFX, to implement your own interpolator, you
can either start from scratch and extend the Interpolator abstract class, where you will be
responsible for providing your own interpolation algorithm. Or, you can extend the ready-made
SimpleInterpolator class, which implements a simple linear algorithm.
For the implementation of the MagneticInterpolator class, we use the latter approach and
extend SimpleInterpolator , because we expect values to be calculated in a linear fashion.
The MageneticInterpolator class exposes a property called attraction:Number which,
to keep things simple, is the t value beyond or below which (depending on direction) will snap
to the final target value. As shown in the previous figure, when the Interpolator goes past time
value t a the location of the circle along the x-axis snaps to 375 .
 
Search WWH ::




Custom Search