PFA:005 – Arrays and Loops, Installing Libraries

Inspiration – Large-Scale Projects & Collaboration

Today’s Artists

Arrays

Loops (for)

  • for – This is what we are mainly going to use. Used when you need to repeat something a very specific amount of times.
  • while – We are not going to use this so much, but good to know it exists. Used mainly when you need to repeat something, but you don’t know exactly how many times. (waiting for an input, waiting for a status to change, waiting for a connection to something etc.)

How to Use Arrays in Processing

Declaring Arrays

Looping through Arrays

How the for Loop Works

Coming soon…

Examples

Random Walker

Random Walkers with Arrays

Random Walkers with More Arrays

Libraries

Video

If you try to search for video in the Processing language reference, you will notice that there is nothing to be found. The reason for that is that video playback is not part of the core Processing functionality, you need to use an additional library.

Libraries are collections of code that extend the functionality of Processing. There are a couple of libraries that are built-in (such as Serial and Network), but most of them need to be installed from the Library Manager. (Sketch–>Import Library—>Add Library)

screen-shot-2016-10-14-at-02-31-55

Search for the official Video library from The Processing Foundation and install it.

screen-shot-2016-10-14-at-02-34-37

The best way to figure out how the library works, is to go through the examples that come with it. Note that the functionality is split into two main classes:

  • Movie: used to play video files. The library is a bit fussy about the codec of the video. H264 .mov files seem to work well.
  • Capture: Used to capture the image from a webcam connected to the computer.
screen-shot-2016-10-14-at-02-41-29

Sound

Playing sound in Processing also requires an external library. Try these libraries:

  • Sound library – The official sound library from the Processing foundation (has some bugs and issues. Especially on Windows)
  • Minim library – Often works better, so let’s use this mainly
screen-shot-2016-10-14-at-02-42-47

There are some other sound libraries also, if you need to do something more specific.

Again the best way to learn how it works is to go through the examples.

Other Useful Libraries

You might want to install some additional libraries while you are at it. Some of the features might be beyond your skill level right now, but the libraries listed below are some interesting ones that you might want to come back to later. I added links to the libraries, but you should be able to install these directly with the Library Manager.

  • List of Processing libraries – Don’t just listen to my suggestions, check the list to find the libraries that would be useful for you.
  • Arduino (Firmata) – For controlling Arduino from Processing
  • Box2D – Physics library
  • controlP5 – Add GUI elements
  • oscP5 – OSC library for Processing. Very useful for connecting Processing to some other software (like Pure Data).
  • Open Kinect for Processing – For working with the Kinect sensor.
  • Syphon – Used for sharing frames between applications
  • toxiclibs – A collection of useful tools (physics, simulation

Assignment: Project Proposal for Your Final Project

Send me a project proposal as a pdf file: