JavaFX: Bloom and Glow Classes
Here, you find out how to make your ordinary JavaFX shapes bloom and glow, all with the help of two simple classes, unsurprisingly named Bloom and Glow. This table shows the members of these two classes.
|Bloom()||Creates a new Bloom effect with default parameters.|
|Glow()||Creates a new Glow effect with default parameters.|
|void setThreshhold(double value)||Sets the luminosity threshold. The bloom effect will be applied
to portions of the shape that are brighter than the threshold. The
value can be 0.0 to 1.0. The default value is 0.3.
|void setLevel(double value)||Sets the intensity of the effect’s glow level. The value
can be 0.0 to 1.0. The default value is 0.3.
The figure shows the effect of the Bloom and Glow effects. All three of the text shapes shown in the figure are combined with a rectangle in a group. The following code was used to create the first group (shown at the top of the figure):
Rectangle r1 = new Rectangle(50, 50, 400, 100); r1.setFill(Color.BLACK); r1.setStroke(Color.BLACK); Text t1 = new Text("Plain Text"); t1.setX(130); t1.setY(125); t1.setFont(new Font("Times New Roman", 60)); t1.setFill(Color.LIGHTGRAY); Group g1 = new Group(); g1.getChildren().addAll(r1, t1);
Similar code was used to create the second group (shown in the middle of the figure), but a Bloom effect was added:
Rectangle r2 = new Rectangle(50, 50, 400, 100); r2.setFill(Color.BLACK); r2.setStroke(Color.BLACK); Text t2 = new Text("Blooming Text"); t2.setX(70); t2.setY(125); t2.setFont(new Font("Times New Roman", 60)); t2.setFill(Color.LIGHTGRAY); Group g2 = new Group(); g2.getChildren().addAll(r2, t2); Bloom e1 = new Bloom(); e1.setThreshold(0.3); g2.setEffect(e1);
For the third group, a Glow effect was added instead:
Rectangle r3 = new Rectangle(50, 50, 400, 100); r3.setFill(Color.BLACK); r3.setStroke(Color.BLACK); Text t3 = new Text("Glowing Text"); t3.setX(80); t3.setY(125); t3.setFont(new Font("Times New Roman", 60)); t3.setFill(Color.LIGHTGRAY); Group g3 = new Group(); g3.getChildren().addAll(r3, t3); Glow e2 = new Glow(); e2.setLevel(1.0); g3.setEffect(e2);
The difference between the bloom and glow effect is subtle. To be honest, it’s barely noticeable. If you look very closely, you’ll see that the glowing text is just a tad brighter than the blooming text. (The distinction between glow and bloom is more noticeable when colors other than black and white are used.)