Installing libraries
The core functionality of Processing is very basic. This was done by design, to make it easy for everyone to get started using it. If you need to do something that's not available in Processing, you can use a library that adds the functionality you need. One of the new features in Processing 2 is the Library Manager. This allows you to install new libraries in the easy way.
Getting ready
There is an overview of the available Processing libraries on the Processing website at http://processing.org/reference/libraries/. You'll find the documentation of the libraries included with Processing and a list with contributed libraries. There are libraries to work with 3D, computer vision, geometry, and a lot more.
How to do it...
You can open the library manager by using this menu: Sketch | Import Library… | Add Library…. This will give you a list of available libraries. To install the library you need to select it from the list and click on the Install button. Processing will install the library in the libraries folder of your sketchbook.
Unfortunately, not all libraries are included in this list. Some of the older libraries will probably still work in Processing 2, but the developer might not have added the new functionality to install the library through the Library Manager. In that case, you'll need to install the library manually. Don't worry; this is not as hard as it sounds.
You should download the library from the website of the developer and unzip it. Drag this folder to the libraries
folder inside your sketchbook. Libraries are structured in a (predefined) way. If the library is not structured like this, it won't work. The main library folder usually contains four subfolders: examples
, library
, reference
, and src
. The examples
folder contains Processing sketches the developer made to show how the library works. The library
folder contains the compiled library code that will be imported into your sketch. The reference
folder stores the documentation on how to use the library. The src
folder contains the source code of the library. This might be handy for advanced users to learn how the library works and modify it as per their needs.
How it works...
The folder structure for libraries is important for Processing to find the library. The main folder for the colorLib library is named colorLib. Inside the library folder within that directory, you'll find a file named colorLib.jar. This JAR file will be included in your applet or application when you export your sketch. You can add import libraries into your sketch by going to the Sketch | Import Library… menu and select the library you want.