04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Interactivity<br />

Figure 4-13. Puff<br />

People take for granted that when a mouse or other pointing device is connected to their<br />

computer, the computer will respond to all their wants <strong>and</strong> desires—or at least clicks.<br />

Obviously, the computer needs a little more motivation than that. Mouse presses, releases,<br />

hovers, enters, exits, moves, <strong>and</strong> drags are all loosely classified as mouse events, which can<br />

be further classified more generally as simply events. Event h<strong>and</strong>ling is the basis of interactivity.<br />

Events can be mouse behavior, but they can also be window events (resizing a window),<br />

keyboard events (pressing a key), menu events (selecting from a pull-down menu),<br />

or focus events (selecting a dialog window, palette, or text field as the active area, which<br />

usually then accepts additional input such as filling in a text field with a word). Essentially,<br />

any input or state change that the computer can detect can be processed as an event.<br />

There are two main aspects to interactivity or working with events: event detection <strong>and</strong><br />

the event h<strong>and</strong>ling.<br />

Event detection<br />

COMPUTER GRAPHICS, THE FUN, EASY WAY<br />

<strong>Processing</strong> <strong>and</strong> Java have a built-in low-level event detection mechanism, which is a good<br />

thing. If they didn’t, we would be forced to create an endless event loop, constantly checking<br />

to see if events were occurring. This approach, called polling, is complicated <strong>and</strong> eats<br />

up CPU cycles (CPU processing time). Part of the reason it is potentially confusing deals<br />

with the very nature of how the computer works. A single-processor machine (with one<br />

CPU) ultimately needs to h<strong>and</strong>le one operation or process at a time. The CPU might be<br />

139<br />

4

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

Saved successfully!

Ooh no, something went wrong!