Making A Processing Library

AUlogoWhile programming in Processing, I’ve developed about a dozen useful tools for everyday work. I’ve packaged these up in a library which I call AU, for “Andrew’s Utilities.” I’ll be sharing it as soon as I finish the documentation. Although the official Processing wiki has a nice walkthrough for how to make a library, there are a few things that I spent considerable time figuring out. Here’s what I learned, to save you the effort.

First, Processing libraries are not written in Processing! They’re Java. It’s easy enough to convert from Processing to Java, but if you relied a lot on some of Processing’s built-in routines (like map or constrain) you’ll need to touch up your code, either by calling those routines through a pointer back to your sketch, or by re-implementing them locally. You’ll find a lot of the numerical routines (like sin and sqrt) available in Java’s Math library.

Second, I found the template approach described here to be by far the easiest way to go. I used their Option B: Download Package and it worked great.

Third, Step 2 under “Set Up and Compile” wants you to “Open the resources folder inside of your Java project.” I spent a good 20 minutes looking for this. It’s actually inside your template! Open the template folder and there’s your resources folder.

Fourth, while editing build.properties and setting up all the paths for your Processing installation, you can set your classpath.local.location variable in two places (as of template 0.5.3,, lines 32 and 41). Only use one, and leave the other commented out.

Fifth, you’ll see a setting for ant.description. Don’t change it; the default works fine.

Sixth, when it’s time to compile, you want to press the small white triangle in a green circle at the top of the Ant pane. To enable this button, make sure that you have selected the file in the pane (this is the one that was made when you dragged build.xml into the pane, and is probably named ProcessingLibs).

The rest is pretty straightforward if you follow their instructions. The hardest part was making all the little changes from Processing to Java (such as adding the keyword public to things). Their example code calls the parent sketch myParent, but I renamed this to theSketch because I think that’s much more specific and informative.

Leave a Reply

Your email address will not be published. Required fields are marked *