so heres my simple candle.
This is how it is done.
1. Lets create the body of the candle or its trunk. We will going to use the javafx.scene.shape.Rectangle for the trunk and javafx.scene.paint.LinearGradient API to fill color on its trunk. Wel have to use the javafx.scene.effect.GaussianBlur effect to make the trunk more realistic, it also make the edge of the candle more smooth.
var fire = Ellipse {
centerX: bind candlebody.x + 25 centerY: bind candlebody.y - 30
radiusX: 15 radiusY: 30
fill: bind RadialGradient{centerX: 80 centerY: 50
focusX: focusY: 10
radius: 60
proportional: false
stops: [Stop { offset: 0.3 color: Color.ORANGE},
Stop { offset: 0.5 color: Color.YELLOW},
Stop { offset: 1.0 color: Color.BLUE},
] }
effect: MotionBlur { radius: 10 angle: 100 }
}
preview below:3. Lets create the candle thread on top of the candle trunk and make it look like it burns. wel going to use the javafx.scene.shape.Rectangle for the thread and use the javafx.scene.effect.GaussianBlur effect to look like it is burning.
}
effect: MotionBlur {
Stage {
title: "Candle"
width: 300 height: 600
scene: Scene {
fill: Color.BLACK content: [candle]
}
}
preview below:
6. We then make the radiance using the javafx.scene.shape.Ellipse and the javafx.scene.paint.RadialGradient combining 3 colors stop orangedred, orange and white. We then use the javafx.scene.effect.GaussianBlur effect so that the color will spreadout. And then we will make the ellipse slightly transparent so that the flame will still visible using the inherited variable fro the node javafx.scene.Node named opacity and set the value to 0.2.
var fireradiance = Ellipse{
centerX: bind fire.centerX centerY: bind fire.centerX - 25
radiusX: 40 radiusY: 50
fill: bind RadialGradient{
centerX: 80 centerY: 50
focusX: 50 focusY: 10
radius: 60
proportional: false
stops: [Stop {
offset: 0.0 color: Color.ORANGERED},
Stop {offset: 0.5 color: Color.ORANGE},
Stop {offset: 1.0 color: Color.WHITE},] }
effect: GaussianBlur {radius: 60}
opacity: 0.2
}
7. We almost done with our work, lastly we are going goup the candle body variables and have an reflection effect using javafx.scene.effect.Reflection and use javafx.scene.effect.BlendMode set to BlendMode.MULTIPLY.
var candle = Group{
translateX: bind posx translateY: bind posy
and we are Done. please browse the preview output above.
This work of art also is used as reference on the http://www.javapassion.com/ lesson on Java FX Programming (with Passion!)
Wow It's like real candle.
ReplyDeletethanks, you can do better than that, using JavaFX. Have a try and the feel how of fun and easy doing it.
ReplyDeleteThanks for such useful information.
ReplyDelete