Java Reference
In-Depth Information
var rotate = Rectangle{
translateX: width + 80
translateY: 90;
width: 70
height: 70
fill: Color.MAGENTA
rotate: bind currentValue*360.0
}
insert rotate into content;
}
}
Listing 5-2 shows the class
InterpolatorView,
which extends
Group
. Setting the property
interpolator
, which populates the content by calling the function
draw
, controls the visual appearance
of this
Node
.
The function
draw
creates a graph that displays an
Interpolator
as a function of time. The function
draw
also creates several animated components. The first is a red line that moves across the graph to
show which value of the Interpolator is being expressed by the other components.
The other two components are a green dot that moves vertically with the value
currentValue
and a
rotating square, which is also synchronized with the
currentValue
.
Built-In Interpolators
The interpolators that come with JavaFX are just enough to whet the appetite. All of the built-in
interpolators can be accessed by static calls to the class Interpolator, as shown in the first example. A
description of each interpolator follows and is demonstrated in the companion code.
Linear
The linear interpolator is the default interpolator used by
KeyFrame
. It is not much of an
Interpolator
, as
it simply returns the value passed to it. A node being animated with a linear interpolator starts moving
and travels at a constant speed until it suddenly stops at its destination. For the sake of completeness,
Figure 5-1 shows a graph describing the motion over time.