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

738<br />

<strong>Processing</strong> can also render TTF (TrueType) <strong>and</strong> OTF (OpenType) font vector formats, as<br />

long as the font is installed in your sketch’s data directory. Thus, it is possible to distribute<br />

your sketch on the Web or directly to another user with the specific TTF or OTF font<br />

included in the sketch’s data directory. However, there are legal/copyright issues involved<br />

in distributing fonts like this, as the <strong>Processing</strong> reference states: “Only fonts that can legally<br />

be distributed should be included with a sketch” (see http://processing.org/<br />

reference/createFont_.html).<br />

Finally, type in <strong>Processing</strong> can also be rendered in 3D space, although there is some quality<br />

loss for this very cool capability. If quality is critical, use the textMode(SCREEN) comm<strong>and</strong>,<br />

which forces the type rendering to the front of the display window, increasing<br />

rendering quality.<br />

Loading & Displaying<br />

The Loading & Displaying subsection has four main functions that allow fonts to be displayed<br />

in <strong>Processing</strong>, as follows (please note that the <strong>Processing</strong> language reference lists<br />

text() first, but I’ll discuss it last):<br />

text()<br />

createFont()<br />

loadFont()<br />

textFont()<br />

createFont() dynamically converts a font installed on your computer to the VLW format<br />

used by <strong>Processing</strong>. This function works similarly to the Create Font comm<strong>and</strong> in the Tools<br />

menu. However, the createFont() function doesn’t write the converted VLW font to disk<br />

the way the Create Font comm<strong>and</strong> does. While the createFont() function is listed in the<br />

<strong>Processing</strong> online reference as an advanced feature offering precise control, the reference<br />

states that “On most occasions you should create fonts through selecting ‘Create Font . . .’<br />

from the Tools menu.” For more info on this advanced feature, please refer to<br />

http://processing.org/reference/createFont_.html.<br />

To load existing VLW fonts installed in the data directory, use the loadFont() function,<br />

which expects a string of the full font name. No path is necessary if the VLW font is<br />

installed at the root level of the data directory. textFont() allows you to set the current<br />

font, as long as it’s been loaded with loadFont(). Finally, the text() function is what you<br />

call to actually add some type to the screen. text() has numerous forms with regard to<br />

arguments you can pass it, including x, y, z, width, <strong>and</strong> height.<br />

The following typography example I created rotates two text strings in 3D space (see<br />

Figure A-19). I created one of the fonts dynamically <strong>and</strong> loaded the other out of the<br />

sketch’s data directory. In creating the font dynamically, I needed to make sure that I used<br />

a font installed on my computer (I specified Helvetica). If you’re not sure what fonts you<br />

currently have installed, run the following line of code in <strong>Processing</strong>:<br />

println(PFont.list());

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

Saved successfully!

Ooh no, something went wrong!