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

Create successful ePaper yourself

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

entering CMD). When using a comm<strong>and</strong>-line shell instead of a GUI shell, you need to be<br />

explicit when issuing comm<strong>and</strong>s. It is common for modern GUI shells to hide the suffixes<br />

of files. In OS X, to launch the Calculator application using the Finder (GUI shell), you<br />

double-click the calculator icon, named simply “Calculator.” In contrast, from the Terminal<br />

application (comm<strong>and</strong>-line shell), you need to type: open Calculator.app. In addition, you<br />

need to be explicit as to where files reside (the path) to access/launch them. When using<br />

relative paths with <strong>Processing</strong>’s open() comm<strong>and</strong>, you need to provide path addresses in<br />

relation to the <strong>Processing</strong> application. For example, the <strong>Processing</strong> application on my computer<br />

lives within a <strong>Processing</strong> directory, which lives in the Applications directory. The<br />

Calculator application also lives within the Applications directory. To launch the<br />

Calculator on a mouse press, I can use the following <strong>Processing</strong> sketch:<br />

void draw(){<br />

}<br />

void mousePressed(){<br />

open("../Calculator.app");<br />

}<br />

The open() comm<strong>and</strong> also allows to you pass a String argument. You can read more<br />

about open() at http://processing.org/reference/open_.html.<br />

Web<br />

The Web section includes the functions link(), param(), <strong>and</strong> status(). Stating the obvious,<br />

these functions involve web-based features <strong>and</strong> are used within a browser environment.<br />

link() allows you to load a web page, as well as specify which browser window to<br />

use (the existing one or a new one). param() reads the value of a parameter, specified<br />

within the HTML of a web page. For example, if you have the following HTML in the page<br />

holding an applet, created from a sketch named SimpleBall:<br />

<br />

<br />

you can use the param value ballradius in your SimpleBall sketch:<br />

// SimpleBall sketch<br />

String strgRadius = param("ballradius");<br />

int radius = Integer.parseInt(strgRadius);<br />

size(200, 200);<br />

ellipse(width/2, height/2, radius, radius);<br />

You’ll notice that the param value comes back as a String, so it needs to be converted to<br />

a number. Integer.parseInt() is a static method of Java’s Integer class that converts<br />

strings to integers. (Remember, in <strong>Processing</strong>, you can use Java code along with <strong>Processing</strong><br />

code.)<br />

status() allows you to display messages in the browser’s status area—normally in the<br />

lower-left corner of the browser.<br />

PROCESSING LANGUAGE API<br />

707<br />

A

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

Saved successfully!

Ooh no, something went wrong!