Java Reference
In-Depth Information
Figure 6.17
Sphere with Reflection Effect
Blending
Blending enables you to combine two inputs together to form a composite output
by selecting one of the predefined BlendMode s. The JavaFX API spells out
approximately 20 of these; we'll demonstrate a few with straightforward exam-
ples so that you get a feel for how blending can be used in practice.
For our first sample, we'll compare and contrast the ADD and MULTIPLY BlendMode s
by intersecting a magenta-filled rectangle with some green-colored text. The
rationale for choosing these two colors will become apparent as we differentiate
between ADD and MULTIPLY, which are described in Table 6.3.
Ta b l e 6 . 3
ADD and MULTIPLY BlendModes
BlendMode
Description
ADD
The individual color components (R, G, B) and alpha value (transparency)
are added together to form new component values. In the case where the
sum of any component exceeds the maximum component value, it is capped
to the maximum value.
MULTIPLY
The individual color components (R, G, B) and alpha value (transparency)
are multiplied together to form new component values. In the case where the
product of any component exceeds the maximum component value, it is
capped to the maximum value.
Listing 6.4 demonstrates how to blend two inputs together using the ADD BlendMode .
Listing 6.4
Demonstrating BlendMode.ADD
import javafx.scene.shape.*;
import javafx.scene.paint.*;
 
Search WWH ::




Custom Search