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

710<br />

Output<br />

This section involves outputting data, both to the screen <strong>and</strong> to a file. As in the Input section,<br />

<strong>Processing</strong> makes these relatively low-level processes really easy to perform. This<br />

section is divided into three subsections:<br />

Text Area<br />

Text Area<br />

Image<br />

Files<br />

Text Area is a simple category that includes the two functions print() <strong>and</strong> println(). Both<br />

output to the text area in the <strong>Processing</strong> window, but println() adds line returns<br />

between each call to the function. You can use the string concatenator + within the argument<br />

string, passed to the print() or println() function. For example, the following<br />

code outputs I love <strong>Processing</strong>:<br />

Image<br />

String name = "<strong>Processing</strong>";<br />

print("I love "+name);<br />

Image includes two very cool functions that allow you to save screen image data to the<br />

sketch directory. saveFrame() will actually save a sequence of images in TIF, TGA, JPG, or<br />

PNG format. You can then import these sequenced images into video editing software <strong>and</strong><br />

produce movies of your <strong>Processing</strong> animations. save() just saves the current screen<br />

image. Please note that neither of these functions will work when running your sketches<br />

from within a web browser. This is a limitation of Java applets in general, imposed by Sun<br />

to “keep applets from compromising system security,” as mentioned in the article “What<br />

Applets Can <strong>and</strong> Can’t Do” (see http://java.sun.com/docs/books/tutorial/deployment/<br />

applet/security.html). To learn more about Java applets, check out http://java.sun.<br />

com/docs/books/tutorial/deployment/applet/index.html.<br />

Files<br />

The Files subsection of the Output section is similar to the Files subsection of Input, except<br />

things work in reverse. The two functions saveStrings() <strong>and</strong> saveBytes()—as you might<br />

guess—save strings <strong>and</strong> bytes, respectively, to files within the current sketch directory.<br />

There are also two more general-purpose output functions, beginRecord() <strong>and</strong><br />

endRecord(), which can be used to write out drawing functions as well as the contents of<br />

the display window (just be sure to call beginRecord() before the drawing calls you want<br />

recorded). To use these functions, you need to explicitly specify a renderer <strong>and</strong> file name<br />

as arguments in the beginRecord(renderer, filename) call.

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

Saved successfully!

Ooh no, something went wrong!