My Processing Template Sketch

Posted by Jan Vantomme on 29 November 2010.
Tags: , ,

Processing makes it very easy to save your work in different formats. But writing the code to save movies, images and PDF files from the same sketch is boring. I’ve made a template sketch I can reuse so I don’t have to write this kind of code over and over again. The template consists of three files:

  • template.pde Main template sketch.
  • config.pde A configuration file with the directories to save images, PDF files, movies and the number of frames for the length of the movie.
  • functions.pde Some functions to generate filenames for the PDF and video files.

If you’re familiar with Processing, you should be able to figure out what everything in this sketch is doing. I’ll only explain the basic idea behind it in this article.

Main Template

Most of the magic happens in the draw() method. The first block of code starts recording a new PDF or video file. The second part is where I do all the drawing. The third part finishes recording the PDF file, adds a frame to the video file and finishes the file after a certain amount of frames set in the config file, and saves images.

I’m using the ANIMATION codec at LOSSLESS quality, Full HD so I usually end up with big video files. This is handy if you need to do some post-production.

Configuration File

The configuration file has three String variables I use for the directories to which each type of file gets saved. I don’t like my files ending up in the same directory. The maxFrames variable is used to set the length of the movies. I’m using 750 frames at 25 frames per second so I end up with 30 seconds of video.

bcString IMAGE_DIRECTORY "images/";
String PDF_DIRECTORY   "pdf/";
String VIDEO_DIRECTORY "movies/";
int maxFrames 750


  • getSketchName() returns a String with the name of the current sketch. This function is called when I save images and when I need to generate a new filename for a PDF or video file.
  • newVideoFileName() returns a String with a new filename for a video file. The filename is made from the VIDEO_DIRECTORY, the sketch name, a five digit random number and the .mov extension.
  • newPDFFileName() is basically the same as newVideoFileName(), but it returns a string for a new PDF file.

User Interface

  • s Save the current frame as a PNG file.
  • p Save the current frame as a PDF file.
  • m Start recording a new video file.


Download my Processing Template sketch.

Tweet this article

Oldskool Comments (1)

Gravatar for Katia

From: Katia
Date: 05.12.2010

Bedankt voor de tips! Dat filmpje is wel niet geschikt voor gevoelige kijkers; ik ben er nog niet goed van.

Top · Permanent link to this comment