09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5/Response<br />

Code that responds to input from the<br />

mouse, keyboard, and other devices has<br />

to run continuously. To make this happen,<br />

place the lines that update inside a<br />

Processing function called draw().<br />

Once and Forever<br />

The code within the draw() block runs from top to bottom, then<br />

repeats until you quit the program by clicking the Stop button or<br />

closing the window. Each trip through draw() is called a frame.<br />

(The default frame rate is 60 frames per second, but this can be<br />

changed).<br />

Example 5-1: The draw() Function<br />

To see how draw() works, run this example:<br />

void draw() {<br />

// Displays the frame count to the Console<br />

println("I'm drawing");<br />

println(frameCount);<br />

}<br />

You’ll see the following:<br />

I'm drawing<br />

1<br />

I'm drawing<br />

2<br />

I'm drawing<br />

3<br />

...<br />

In the preceding example program, the println() functions<br />

write the text “I’m drawing” followed by the current frame count<br />

49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!