The Coder's Handbook   

Using Processing


An Example Program

First, open up processing.  You’ll see a blank project with some weird name like sketch1032890.   


void setup()


   frameRate(1);             // slows the program to run 1 frame per second

   println("Hello World");   // prints Hello World then starts a new line


void draw()


   print("*");               // prints a * each frame on the same line


Output after 1 second

Hello World


Output after 1 second, assuming frameRate is 5:

Hello World


Output after 1 second, assuming frameRate is 30:

Hello World


Output after 1 second if you delete the frameRate() line.  This program runs at 60 frames per second.

Hello World



Using Comments

A comment is a section of coder that doesn't have any effect, but acts as a note for the reader.

You can write comments in your code in two ways:


void setup()


   // This is an inline comment

   /* This is an extended

       comment */



In processing you can select a whole block of code and press CTRL-/  (control and forward slash).  Doing so will turn that whole section into a comment.  You can do so again to turn the same code back to normal.

This is super useful for temporarily disabling code when debugging. 


Setup and Draw

In Roboquest, every program started with the go() method.  In a normal processing program, you have two “main” methods, called setup() and draw().


The Console 

The black window where Processing output text is called the console.  This is commonly used for text-based programs, but also for debugging our code.  Sometimes it helps to print out the value of a variable, or information about what is going on.


There are two ways to print information:

The console in Processing isn't quite as fun as the one you might have at home...