Java Reference
In-Depth Information
Figure 14-5 shows shapes displayed from top to bottom starting with an ellipse, rect-
angle, and a rounded rectangle having colored gradient fills. When drawing the eclipse
shape, you will be using a radial gradient that appears as if it were a 3D spherical ob-
ject. Next, a rectangle filled with a yellow semitransparent linear gradient is created. A
thick black line shape was drawn behind the yellow rectangle to demonstrate the rect-
angle's semitransparent color. Lastly, a rounded rectangle filled with a green-and-black
reflective linear gradient resembling 3D tubes in a diagonal direction is generated.
The amazing thing about colors with gradients is that they can often make shapes
appear three-dimensional. Gradient paint allows you to interpolate between two or
more colors, which gives the shape depth. JavaFX provides two types of gradients: a
radial ( RadialGradient ) and a linear ( LinearGradient ) gradient. A radial
gradient ( RadialGradient ) is applied to the ellipse shape in the example.
Table 14-1 is taken from the JavaFX 8 Javadoc definitions found for the Radi-
alGradient class ( http://docs.oracle.com/javase/8/javafx/api/
javafx/scene/paint/RadialGradient.html ) .
Table 14-1 . RadialGradient Properties
Property
Data Type
Description
Angle in degrees from the center of the gradient to
the focus point to which the first color is mapped
focusAngle
double
Distance from the center of the gradient to the focus
point to which the first color is mapped
focusDistance
double
X coordinate of the center point of the gradient's
circle
centerX
double
Y coordinate of the center point of the gradient's
circle
centerY
double
Radius of the circle defining the extents of the color
gradient
radius
double
Coordinates and sizes are proportional to the shape
that this gradient fills
proportional
boolean
Cycle method applied to the gradient
cycleMethod
CycleMethod
opaque
boolean
Whether the paint is completely opaque
Gradient's color specification
stops
List<Stop>
In this recipe, the focus angle is set to zero, the distance is set to .1, the center X
and Y are set to (80,45), the radius is set to 120 pixels, the proportional is set to false,
 
 
Search WWH ::




Custom Search