All of the shapes we have used so far have been rendered pretty bland with boring solid colors. Let's say you want to enhance the look of your objects by adding depth for a more engaging look. This recipe shows you how to use the Effect
classes to add lighting and shadow effects to visual nodes in the scene graph.
All Node instances can receive an effect through the effect:Effect
property. You can find all effects in the package javafx.scene.effect
. For this recipe, we are going to use effects classes Lighting, DistantLighting
, and DropShadow
.
The abbreviated code listing given next shows you how to use the Lighting and the DropShadow effects to enhance the appearance of a circle and a rectangle. You can find the the full listing in ch03/source-code/src/effects/ShapeEffectDemo.fx
.
def shadow = DropShadow { offsetX:5 offsetY:5 } def light = Lighting { light:DistantLight{azimuth:-45} surfaceScale:5 } def circ = Circle...