Griffon: Clojure powered fractal - No Fluff Just Stuff

Griffon: Clojure powered fractal

Posted by: Andres Almiray on July 31, 2009

Stumbled upon this page while searching for Clojure examples to try out with Griffon's brand new Clojure plugin. The provided example demonstrates how Clojure can be used in conjunction with Java2D to generate a Tree-like fractal, naturally I thought "hey, I bet it can be translated into a simple Griffon/Clojure app!". The following picture shows the result of this experiment



Now allow me to show you how it is done.
  1. First, grab a copy of Griffon 0.1.2 if you haven't done so already.
  2. Let's create the app, type griffon create-app fractal on your command prompt.
  3. Go into the app's directory and type griffon install-plugin clojure, this will install the latest version of the Clojure plugin, along with the LangBridge plugin.
  4. Alright, in order for the view to be able to call the drawing code written in Clojure we need an interface, let's call it FractalPainter. Go into src/interfaces and create a file named fractal/FractalPainter.groovy with the following content
  5. Good, now for the actual Clojure code. Go into src/clojure and create a file named fractal/ClojureFractalPainter.clj with the following code
    The code is pretty much the same as the original, apart from changing the name of the main entry point from draw to paint.
  6. Last piece of the puzzle is the view script itself, here we will call the ClojureFractalPainter.
  7. Run the application by typing griffon run-app.
As you can see, the view script is able to call an instance of ClojureFractalPainter implementation as if it were a regular Java class. Well, because it actually is. That is what the :gen-class macro does.

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 »