
Transforming the JavaFX version into Groovy was, for most of it, pretty straight forward though some issues were found along the way, first let me show you the code as it currently looks
In case you're seeing GraphicsBuilder code for the first time know that I made use of property aliases, which means that fill can be set as f, color as c an so on. Alright, let's visit those gotchas
- line 13: radialGradient requires a radius as it doesn't infer it from its host, it also does not follows the shape of its host (as it is the case on JavaFX), this means that it will always have a circular profile.
- lines 35-44: decided to improve the way the cup shape is created by using an intersect operation, problem is that the resulting shape didn't accept a nested paint node, that is why I had to save it as shape an then draw it again. When a shape is drawn this way it looses all local transformations, that is why a keepTrans property had to be set to true. While powerful the usage of draw is not intuitive.
- line 57-60: this is not exactly a problem but a plus, as the innerRim shape is reused to create a composite shape based on an intersect operation.
- lines 62-66: a local transformation is applied to the cup group, negative translation coordinates had to be specified given the relationship with the scale transformations, in other words, scaling is done at world coordinates, not local coordinates.
Keep on Groovying!