PFA:004 – Text/Images/Video/Sound

Inspiration

Artists

Text

If you don’t care about the font of your text, you can just use the command text() to draw text on the screen with a generic sans-serif font.

text("wow",100,100);

If you would like to have more control, you can load a specific font for drawing your text. There are two ways to do it:

  • loadFont(): loads a font file from a folder called data inside your sketch folder. The font needs to be in .vlw format. You can create .vlw files with the Create Font tool (Tools–>Create Font)
  • createFont(): You can also use any font installed on your system with the createFont(). It will dynamically convert your font to the correct format.

Check the reference and the examples for more details on how to use the text tools.

Images

In order to display images in Processing, we need to use the PImage class.

PImage photo;

void setup() {
  size(640, 480);
  photo = loadImage("imageFileName.jpg");
}

void draw() {
  image(photo, 0, 0);
}

Where does the file have to be?

  • You can have the image file on your computer. It needs to be saved in a folder called data inside your sketch folder.
  • You can also use an url to load an online image.

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. Search for the Sound library.

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.

4th Assignment

No need to return anything today, since OpenProcessing doesn’t really work so well if you try to work with external files. Enjoy your weekend!

I would still recommend exploring the examples in more detail. Try finding things that are relevant to your interests.