Let's see a simple example of gradients in action, the following image displays 4 gradients

Here is the snippet of graphics operation that produced that image
As with other graphics operations available in GraphicsBuilder
gradientPaint()
provides sensible defaults for its properties in case you were wondering where the colors come from. You may have also noticed that the gradient's bounds are smaller than the actual shape bounds, still the gradient fills the whole shape; also the starting point of the gradient (which is the color black) matches one corner though no transformations is visible. This happens because gradientPaint()
has been adjusted to the shape's bounds with the default setting of fit=true
meaning that the gradient will be scaled (retaining its original bounds ratio). There is another setting stretch=true
that will scale the gradient to the shape's bound, discarding the original ratio. Gradients can also have cycles if cyclic=true
is specified. As you may have guessed these 3 settings exclude one another, if one is true the others will be set to false. Let's see those settings at work, while at the same time taking advantage of the fact that any paint may be used as a parameter for the fill
property on any shape operation.This is the base code
These are the outputs with different settings for fit, stretch and cyclic
fit = true![]() |
fit = false![]() |
stretch = true![]() |
cyclic = true![]() |
I expect to have full gradient support in the next version of GraphicsBuilder (0.4.2), stay tunned for more GraphicsBuilder news.
Keep on Groovying!