O'Reilly logo

Getting Started with Processing.py by Casey Reas, Ben Fry, Allison Parrish

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Response

Code that responds to input from the mouse, keyboard, and other devices has to run continuously. To make this happen, place the lines that update inside a Processing function called draw().

Once and Forever

The code within the draw() block runs from top to bottom, then repeats until you quit the program by clicking the Stop button or closing the window. Each trip through draw() is called a frame. (The default frame rate is 60 frames per second, but this can be changed.)

Example 5-1: The draw() Function

To see how draw() works, run this example:

def draw():
  # Displays the frame count to the Console
  print "I'm drawing"
  print frameCount

You’ll see the following:

I'm drawing
1
I'm drawing
2
I'm drawing
3
...

In ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required