linearGradient
and radialGradient
after getting gradientPaint()
to work. One may think that gradientPaint
and linearGradient
are pretty much the same but there are 3 differences- linearGradient supports more than twp colors at a time.
- linearGradient supports 3 cycle modes.
- linearGradient is only available since jdk6.
linearGradient
and radialGradient
require a nested set of stop
operations (at least 2 or they will bomb, watch out for that). Let's revisit the previous examples of gradients but this time with linearGradient

The code is a little more verbose this time, but because builders allow any groovy code we can take advantage of variables and looping costructs to trim some lines

As with
gradialPaint
this operation also allows fit
and stretch
; cycle
may have 3 different values ['nocycle','reflect','repeat']fit = true![]() |
fit = false![]() |
stretch = true![]() |
|
cycle = reflect![]() |
cycle = repeat![]() |
Similar to other gradient paints,
radialGradient
will transform the paint according to the shape's bounds, in this case it will translate the center (cx,cy) and the focus (fx,fy) unless absolute=true
is specified. Let's see a quick example
Notice that the second square is moved 25 pixels to the right but the gradient is not, because it has been marked with
absolute=true
.The code is already available at the svn repo, more to come in the following days.
Keep on Groovying!