Skip to content

Getting Started with Clojure & Processing

2012 February 28
by Tedb0t

For the past little while here at the studio, there’s been a lot of buzz and conversation about Clojure, a modern LISP language that runs on the Java Virtual Machine.  It’s a fascinating language that can help anyone learn about functional programming.  There are a variety of interesting resources for learning Clojure, but I find it’s most fun when your code can make something happen on your screen instantly, like Processing does for Java.

As such, my friend Tims Gardner and I were talking about putting together a class on Clojure & Processing using Roland Sadowski’s clj-processing bindings and Arthur Edelstein’s Clooj IDE.  So, to make things as fast and easy as possible for people to get started, I made a Clooj/Processing Starter Project that you can download and start using right away!  Here’s what you need to do.

  1. Clone or Download the Starter Project into a directory of your choice
  2. Download Clooj standalone and run it
  3. In Clooj, do Project > Open… and point at your new CloojProcessingProject folder
  4. Click on one of the example scripts in the src/ directory
  5. Hit Command-E to run it.
  6. Enjoy! Note that you don’t have to close the applet window to change the code—try changing some code in the (draw) function and hit Command-Enter. Voila, the applet reflects your changes without restarting it! (This is buggy in OpenGL at the moment but works well for regular sketches.)
  7. For reference to the names of Processing functions in clj-processing, refer to the core source (for now).
  8. Note that as clj-processing is changed, the library (processing.core.jar) included may not; I’m including it pre-built for ease of use and setup.  I will try to update it as necessary, though!

For OpenGL Support

  1. I made a startClooj.sh script that you need to run instead of just double-clicking on Clooj. Do chmod +x startClooj.sh (if necessary) and then ./startClooj.sh.
    1. Why is this necessary? For whatever reason, to enable OpenGL support, java has to be started with the java.library.path set to the path of Processing’s OGL dynamic libraries. These are different for different operating systems, so I’m not including all of them here. Hence, you’ll need Processing installed.
    2. The script assumes that:
      1. You have Processing installed in /Applications. If you don’t have Processing, download it and put it wherever, and change the startClooj script to point at it.
      2. Clooj is in /Applications and is named clooj-0.2.8-standalone.jar. If not, just change it in the script.

Learning Clojure

Licensing

My understanding is that Processing’s libraries (core.jar, gluegen-rt.jar, jogl.jar and opengl.jar) are licensed under the GNU Lesser General Public License, so I’m including them here for ease of use.

Related Posts:


2 Responses leave one →
  1. Arthur Edelstein permalink
    February 29, 2012

    This sounds really fun — I’ll have to give it a try. As you say, there’s a lot left to do to make clooj easier to work with — I’d be glad to hear any suggestions on making things more elegant. One thing that might help the workflow is to put the various needed jars in Clojars or another public maven repo and then use leiningen to set up the directories.

    • March 1, 2012

      Thanks! I really like Clooj because it’s a very quick start for teaching a class with—nothing has to be installed.  I’m not familiar yet with maven and leiningen (just know of them).  For the short term I may just put up a repo with the already compiled binaries and example scripts, as long as it doesn’t conflict with Processing’s license. Great to hear from you, and thanks for making Clooj!

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS