Java Reference
In-Depth Information
C H A P T E R 4
■ ■ ■
Effect: Animated Lighting
As you glance around any room, it becomes apparent that though every object is illuminated subtly from
many angles, one light source tends to dominate the others. The light from this main source makes one
side of an object appear bright and the other side dark, often with a smooth gradient transitioning
between the two. The human eye uses this difference between the light and dark to estimate an object's
size and shape. When light moves across an object, the eye and brain get a chance to confirm the
guesses, providing certainty about the nature of the object.
Simulating light in an application is an old trick; both the beveled corners of the 90s and the over-
glossy buttons of the 2000s are ways of simulating light. As animations become increasingly common in
everyday computing tasks, the opportunity to take advantage of animated light to produce convincing
effects also increases. This chapter explores the basics of lighting in JavaFX and how to animate it.
Lighting Basics
Every node in JavaFX has a property called effect . JavaFX comes with a number of built-in effects to give a
Node a unique look. Among these is Lighting , which is used to illuminate a Node in a realistic way. The
Lighting effect can also give an otherwise flat-seeming node a 3D look. A lighting effect can cast light
on a single Node , or all nodes in a Group . Simply placing a light in the scene will not illuminate all Nodes in
the scene unless that light is applied to the root Node . When applying a Lighting effect, there are three
types of lights to choose from. These three types will be familiar to anyone who has worked with 3D
graphics. In fact, two of the three types of lights allow you to specify a Z coordinate, something that is not
common in a 2D graphics library.
Search WWH ::

Custom Search