Java Reference
In-Depth Information
Gradients
Gradients, as defined by the W3C Scalable Vector Graphics Specification , “con-
sist of continuously smooth color transitions along a vector from one color to
another” ( http://www.w3.org/TR/SVG/pservers.html). Once defined, a gradient
can be used as a fill pattern for graphical content. It could be a simple transition
from one color to another, or it may involve multiple transitions and multiple
colors. JavaFX mimics the functionality stated in the SVG spec by implementing
classes that represent the two types of SVG gradients: LinearGradient and
RadialGradient .
Technically, gradients do not belong to the built-in effects subclasses. It just so
happens though that they are oftentimes used to produce effects similar to those
discussed throughout this chapter. For this reason we include gradients here. Our
samples that follow demonstrate, for example, how gradients can be used to
make shapes look more three dimensional.
In keeping with our policy, we'll explain by example. Let's say you want to ren-
der a rectangle where the fill pattern starts out as white on the left side and tran-
sitions to black on the right. The rectangle might look something similar to what
is seen in Figure 6.9.
Figure 6.9
A Rectangle Filled with a LinearGradient
Isolating the JavaFX script code, which describes the rectangle and this particu-
lar fill pattern, would look like this:
Rectangle {
x: 10, y: 10
width: 250, height: 50
stroke: Color.BLACK
fill: LinearGradient {
proportional: true
startX: 0.0, startY: 0.0, endX: 1.0, endY: 0.0
stops: [
Stop {offset: 0.0 color: Color.WHITE},
Stop {offset: 1.0 color: Color.BLACK}
]
}
}
 
Search WWH ::




Custom Search