06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

17<br />

17.1<br />

Text<br />

“ I could entertain future his<strong>to</strong>rians by saying I think all this superstring stuff is crazy. ”<br />

—Richard Feynman<br />

In this chapter:<br />

– S<strong>to</strong>ring text in a String object.<br />

– Basic String functionality.<br />

– Creating and loading fonts.<br />

– Displaying text.<br />

Where do Strings come from?<br />

Text 305<br />

In Chapter 15, we explored a new object data type built in<strong>to</strong> the <strong>Processing</strong> environment for dealing with<br />

images—PImage. In this chapter, we will introduce another new data type, another class we get for free<br />

with <strong>Processing</strong> , called String .<br />

Th e String class is not a completely new concept. We have dealt with Strings before whenever we have<br />

printed some text <strong>to</strong> the message window or loaded an image from a fi le.<br />

println( "printing some text <strong>to</strong> the message window! "); // Printing a String<br />

PImage img = loadImage("filename.jpg"); // Using a String for a file name<br />

Nevertheless, although we have used a String here and there, we have yet <strong>to</strong> explore them fully and<br />

unleash their potential. In order <strong>to</strong> understand the origins of the String , let’s remind ourselves where<br />

classes come from. We know we can create our own classes (Zoog, Car, etc.). We can use classes built<br />

in<strong>to</strong> the <strong>Processing</strong> environment, such as PImage. And fi nally, in the last chapter we learned that we could<br />

import additional <strong>Processing</strong> libraries <strong>to</strong> use certain classes such as Capture or Movie.<br />

Nevertheless, these classes come from our lives in the <strong>Processing</strong> bubble. We have yet <strong>to</strong> venture out in<strong>to</strong><br />

the great unknown, the world of thousands upon thousands of available Java classes. Before we leap over<br />

the Java API cliff (which we will do in Chapter 23), it is useful <strong>to</strong> just peek over the edge and explore one<br />

of the most basic and fundamental Java classes out there, the String class, which we will use <strong>to</strong> s<strong>to</strong>re and<br />

manipulate text.<br />

Where do we fi nd documentation for the String class?<br />

In order <strong>to</strong> learn the details about built-in variables, functions, and classes, the <strong>Processing</strong> reference has<br />

always been our guide. Although technically a Java class, because the String class is so commonly used,<br />

<strong>Processing</strong> includes documentation in its reference. In addition, no import statement is required.<br />

http://www.processing.org/reference/String.html

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

Saved successfully!

Ooh no, something went wrong!