Draw the Groovy logo with GraphicsBuilder - No Fluff Just Stuff

Draw the Groovy logo with GraphicsBuilder

Posted by: Andres Almiray on December 14, 2007

By draw I don't mean get a hold on Groovy's logo image file and paste it on a GraphicsPanel with a quick call to image() but draw it using primitives as star() and text().

Let's take a look at the finished product first, shall we?



It looks good but surely you will notice that the font is not exactly the same, alas I have not found the exact font yet but downloaded one from http://1001freefonts.com because it's name is "Swingtime" :-D ... ok, but where is the code?

Let's see it step by step
  1. Antialias is turn on, we don't want ugly "jaggies" on our logo.
  2. We create the star as a shape so it won't be drawn right away, because we will be applying two transformations that should not be concatenated right away.
  3. The first transformations moves the center over which the star will be rotated, as Star2D (from swingx) draws a five pointed star in a leaned way, meaning the top point is not aligned with the Y axis.
  4. Notice that rotate() treats its angle property as radians instead of degrees (I'll add degree support later) and that its [x,y] properties are optional.
  5. Next we draw the star using a generic drawing operation draw(), which is able to draw any outline/shape operation and java.awt.Shape as well. This operation defines the second transformation applied to the star.
  6. Notice that the saved star shape retains the first transformation
  7. The Swingtime font is loaded from a file, derived to a 50 point size and applied.
  8. Finally the 'Groovy' text is drawn, applying a translate/scale transformation.
  9. Notice that on scale operations you may specify only one of the axis, the other one will be 1 (no change)
A word of caution if you want to try it yourself, this works with the current svn HEAD, not with 0.4.1, as draw() didn't support nesting of transformations and shapes didn't retain any transformations applied to them.

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 »