
I'm not much of an artist so you probably guessed right already, the left one is drawn by GfxBuilder, the right one by FxBuilder; the whole app requires setting up the builders and the following view script
Each sphere is a custom node, notice that the fx version sets a white background by default and also makes the graphics antialiased, whereas in the gfx version you must make those settings explicit, it appears gfxbuilder is in a lower level of abstraction than fxbuilder, but appearances can be deceiving. Let's look at the gfx code first, after all it was used as a reference for making the fx one:
Two things that I really like about this version
- multiPaint() rules!
- java.awt.Color has a derive() method attached via Groovy MOP
On the surface the code is pretty much the same, however there is no multiPaint() equivalent, that makes the code a bit longer, as each gradient must be applied to an independent Circle. Notice that the specular gradient applies requires a scale transform to be applied to the containing Circle not the paint. Also notice that deriving a color is not as easy as calling derive(). This is by no means a post to bash JavaFX rather to point out some of its deficiencies (as well as some of mine, for some reason couldn't get the gradients to use implicit values for cx, cy and r, but I know it's possible somehow!), for example a MultiPaint class could certainly be created, and a derive() method could be added to Color (actually a whole set of deriveRed(), deriveGreen(), etc). The fx version could certainly use some rework, it took me a while to tweak the coordinates to make it look like the gfx version but it is not there quite yet, I'm hoping someone more versed in JavaFX Script can lend a hand. (#imlookingatyoujohnathan)
Oh yeah, in case the first paragraph didn't drive the point home: this is a Swing app that contains two panels, one of them contains a JavaFX scene, so there, it can be done.
Keep on Groovying!