More gradient news - No Fluff Just Stuff

More gradient news

Posted by: Andres Almiray on December 18, 2007

It wasn't that hard as I thought to add 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
  1. linearGradient supports more than twp colors at a time.
  2. linearGradient supports 3 cycle modes.
  3. linearGradient is only available since jdk6.
Because of #1 both 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



Produced with the following code

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!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »