Week 7 Research: Processing Libraries
Updated: Dec 4, 2020
This week's post is about two Processing Libraries that interest me. But first, what is a library? A library is a "collection of 'helper' code which may consist of functions, variables, and objects." These codes allow you to further expand your coding experience. There are libraries that already come with the program ("Built-in Libraries") that you can download straight from the Processing 3 application or on the website and there are third party libraries ("Contributed Libraries") that are made by other people which you can also download on processing.org.
At the end of this post I also threw in the PDF Library and a quick summary of what objects and classes are because I felt it would be useful to research for future sketches in Processing.
Library #1 : Green
Since I have an interest in video games and I'm working on a video game related project for my Thesis, I thought it would be interesting to learn about a library that involves video games.
Green is a contributed library by Zacchary Dempsey-Plante and it's purpose is to make 2D game development with Java easy. It works with two classes: World and Actor. World is the class that holds the interaction and gameplay such as the scene and environment. The Actor class holds all the objects of the game such as the player, items, and obstacles. The Library "provides support for movement, collisions, sprite-drawing at runtime, input detection, different sprite resizing modes, z-indexing, and more" and Zacc also provides a reference and documentation of the library here. I would love to be able to use this library some day soon but need to learn more about coding with Processing to fully understand how to use it.
This is the example he shows. It is a short game he created in 2018 with this library and is the only example I can find for this library but you can view the video on his website here.
Library #2 : Geomerative
This library is a contributed library by Richard Marxer. It "extends 2D geometry operations to facilitate generative geometry" and makes it easier to create generative typography and shapes in Processing by providing a simpler way to use paths, handles and points in geometrical forms.
Example: Generative Typografie - Elien Font 2010
Elien is a monospace generative font created by Tatevik Aghabayan that uses the Geomerative Library. The font uses metaballs which are objects that contain up to five levels of circles within the object and they morph together when interacting with another metaball. Their sizes are random and they are generated along the skeleton of each character in the Latin alphabet and it's punctuations.
Once you open the application you can start typing and the font will be activated. There are controls at the bottom of the application that you can use to control scaling, spacing, density, contrast, levels, dissolve, and to export the content as a PDF.
Example: Cascade On Wheels - Walls Map 2007
Cascade On Wheels was a project by Steph Thirion and was meant to visually portray the amount of cars there are in cities. Walls Map uses the Geomerative Library and is meant to visually show the amount of cars per day in Medialab Prado, Madrid 2006. The streets would become geometric walls and the height of the wall is based on the type of car and the amount that passed by each day. It can be moved around by clicking and dragging on points and paths which is what the Geomerative Library helps create.
I found this to be interesting because I really enjoy seeing different ways to create data visualization. This example also reminds me of Zach Lieberman's Land Lines generative art.
What Are Objects and Classes?
Objects are instances of classes and a class is a grouping of variables and functions you would use to create an object. In other words the class is it's own block of code that you can place anywhere outside of the setup() or draw() that defines the characteristics of single object. Objects can be used to simplify a sketch and repeat a specific graphic multiple times. It is not a variable but uses similar naming principles as a variable would.
To create the object from the class you would need to:
1. Define the global variable at the top of the code
2. Initialize it in setup() by using the new operator.
3. call out it's methods in draw() by using dots syntax
4. Then define the class below the draw() using variables, a constructor, and functions.
Here is an example from the book that creates a moving car object (citation is at the end of this post):
Library #3 : PDF
I felt it would be a good Idea to research the PDF Library and how to use it as it will come in handy in the future.
The PDF library is a built-in library which can be found within the application or on the processing website mentioned above. It is self explanatory in what it does which is it creates PDFs of your static Processing graphics ready for print.
After downloading this library here are the steps for using it:
Import Code: import processing.pdf;
In setup(), use the size() function with "PDF" mode and the filename.
In draw(), insert your coding for the graphic.
Use exit() at the end of your code in draw(). This allows the PDF to finish rendering.
Here is an example of this from the Processing website (PDF Export Library):
No Processing sketch window will appear if you run this code because the PDF mode is meant for high-resolution and complicated images. In order to see what you are working on use the functions: beginRecord() and endRecord().
Example from book (citation is at the end of this post):
The code "endRecord()" can be placed at the very end of draw() so you can view everything you are working on in this PDF mode. You can also use "beginRaw()" and "endRaw()" to render 3D shapes in PDF form.
Other Things You Can Do With The PDF Library
Create multipage documents from frame count.
This examples shows how to create 100 pages by using frameCount == 100 and then using the code "pdf.nextPage()."
Save A Single Frame From An Animation
Use a Boolean to record a single frame from an animation. Use the beginRecord() and endRecord() codes.
Record Multiple Frames Into One File Capture every frame of an animation until told to stop by using beginRecord() and endRecord() and indicating that the letter "q" on the keyboard will stop the rendering.
When working with the PDF Rendering Library, images inserted into the sketch will not look great after rendering. Also, to allow text to be rendered in the PDF you would need to force the text to become a shape by using the code textMode(SHAPE) right after size(). You can also use createFont() or loadFont(). To start a new page in the PDF, use nextPage().
Shiffman, Daniel. Learning Processing a Beginner's Guide to Programming Images,
Animation, and Interaction. Morgan Kaufmann/Elsevier, 2008.