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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

702<br />

Input<br />

This is another large section in the API, generally involved in receiving or inputting data.<br />

Some of these processes are relatively low level, like reading bytes. However, <strong>Processing</strong>,<br />

as you’ve probably come to expect by now, encapsulates <strong>and</strong> simplifies these processes.<br />

The Input section includes 22 functions <strong>and</strong> 9 system variables, divided into five categories.<br />

The categories are as follows:<br />

Mouse<br />

Mouse<br />

Keyboard<br />

Files<br />

Web<br />

Time & Date<br />

The Mouse section includes six properties <strong>and</strong> five functions, used to evaluate when,<br />

where, <strong>and</strong> how mouse input is received by your running sketch. Variables such as mouseX<br />

<strong>and</strong> mousePressed provide live information about the mouse state; mouseX provides the<br />

current x position of the mouse <strong>and</strong> mousePressed returns true or false depending if the<br />

mouse button is pressed. Often, you can use this data creatively—for example, in a drawing<br />

program that colors pixels as the mouse moves over them.<br />

The mouse functions, such as mouseMoved() or mouseDragged(), put code within separate<br />

function blocks (between the curly braces), allowing other functions or comm<strong>and</strong>s to be<br />

called when the mouse motion event is detected. Following is a mouseMoved() example<br />

that illustrates some of the interesting things you can do via mouse detection (see<br />

Figure A-9). There are a bunch of significant concepts within this example, <strong>and</strong> in spite of<br />

it being a bit dense, the sketch is a good base for other experiments. When the sketch<br />

loads, move your mouse over the rectangle.<br />

/*<br />

Box Springs<br />

Ira Greenberg, November 13, 2005<br />

revised October 11, 2006<br />

move mouse over white rectangle<br />

*/<br />

// you can change block count<br />

int blocks = 40;<br />

float margin = 50;<br />

float boxHeight = 75;

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

Saved successfully!

Ooh no, something went wrong!