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 />

590<br />

}<br />

else {<br />

cursor(ARROW);<br />

}<br />

}<br />

The mouse move event code is functionally not very important with regard to actually<br />

moving the square. However, it is critically important with regard to the ergonomics of the<br />

sketch. By changing the cursor <strong>and</strong> adding a rollover state, when the user hovers over one<br />

of the interactive elements, the GUI feels more responsive <strong>and</strong> responds in a more<br />

expected way vis-à-vis other modern software applications. This last example could be<br />

greatly exp<strong>and</strong>ed, particularly through the addition of more GUI components <strong>and</strong> st<strong>and</strong>ardization<br />

of the elements <strong>and</strong> functionality.<br />

Most programming languages have dedicated code libraries or GUI toolkits for h<strong>and</strong>ling<br />

GUI elements (widgets) such as buttons, dialog boxes, sliders, <strong>and</strong> so on. AWT <strong>and</strong> Swing<br />

are two popular Java GUI toolkits for this purpose (see http://java.sun.com/products/<br />

jfc/ for more information on AWT <strong>and</strong> Swing).<br />

Please note that it is not recommended that any AWT or Swing components be<br />

incorporated in <strong>Processing</strong> sketches. For the official statement on this <strong>and</strong> other<br />

GUI-relevant information, check out http://dev.processing.org/reference/<br />

core/index.html.<br />

As of this writing, <strong>Processing</strong> has five (user-contributed) GUI libraries, which you can<br />

access from within the <strong>Processing</strong> application by choosing Help ➤ Reference ➤ Libraries, or<br />

online at http://processing.org/reference/libraries/index.html. I will not be covering<br />

<strong>Processing</strong>’s libraries within this book. The best place to learn more about them is by<br />

searching <strong>Processing</strong>’s online discussion board at http://processing.org/discourse/<br />

yabb_beta/YaBB.cgi. As <strong>Processing</strong> continues to evolve, it’s likely that other GUI libraries<br />

will be created, <strong>and</strong> eventually maybe even a visual editor that will allow you to drag <strong>and</strong><br />

drop pre-made components right into your sketches.<br />

Creating a simple drawing application<br />

Before moving on from the topic of mouse events, I thought it might be fun to create a<br />

simple drawing program. Within this program, you’ll create pencil, paint, <strong>and</strong> eraser tools,<br />

as well as a selectable palette. There are two basic paths you could take here: a vectorbased<br />

drawing program or a raster-based program (of course, you could also combine<br />

the two).<br />

A vector-based program would allow you to select <strong>and</strong> edit the shapes you draw, as in a<br />

program such as Adobe Illustrator. However, programming this level of interactivity comes<br />

at the cost of added complexity (lots of it). With a simpler, raster-based approach, the display<br />

window pixels are colored directly—there is no functionality allowing the selection of

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

Saved successfully!

Ooh no, something went wrong!