Java Reference
In-Depth Information
Applying cool paint effects with gradients
In previous recipes, we have seen the Color class used to apply color to node instances
through the fill property. You may have noticed in some recipes however, that instead of a
simple color instance, you can apply color effects to the fill property. In this recipe, we are
going to explore the gradient color effect.
Getting ready
This recipe uses the concept of gradient paint effects to demonstrate JavaFX's deep support
for rich GUI functionalities. To use gradient paint effects presented in this recipe, you will
need to import classes LinearGradient , RadialGradient , and Stop from the package
javafx.scene.paint .
How to do it...
The abbreviated code listing below shows how to use the gradient classes. You can access the
full code listing from ch03/source-code/src/effects/GradientPaintDemo.fx .
def w = 400;
def h = 200;
def linearGrad = LinearGradient {
startX: 0.0, startY: 0.0, endX: 0.0, endY: 1.0
proportional : true
stops: [
Stop {offset: 0.0 color: Color.RED},
Stop {offset: 1.0 color: Color.BLACK},
]
}
def radialGrad = RadialGradient {
radius:1; centerX: 0.5, centerY: 0.5
proportional : true
stops: [
Stop {offset: 0.0 color: Color.BLACK},
Stop {offset: 1.0 color: Color.WHITE},
]
}
def circ0 = Circle {
centerX: w/2 centerY:h/2 radius: 90 fill: radialGrad
}
 
Search WWH ::




Custom Search