Getting Started with Clojure & Processing
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.
- Clone or Download the Starter Project into a directory of your choice
- Download Clooj standalone and run it
- In Clooj, do Project > Open… and point at your new CloojProcessingProject folder
- Click on one of the example scripts in the src/ directory
- Hit Command-E to run it.
- 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.)
- For reference to the names of Processing functions in clj-processing, refer to the core source (for now).
- 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
- 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
- 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.
- The script assumes that:
- 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.
- Clooj is in /Applications and is named
clooj-0.2.8-standalone.jar. If not, just change it in the script.
- If you’ve never used Clojure before, but are curious to get started, check out these online tutorials:
- Books & Wikibooks:
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.