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

678<br />

Environment<br />

The Environment section contains ten entries for dealing with (getting or setting) global<br />

environment properties. Three of the entries are function calls (which include parentheses)<br />

for setting environmental properties, such as frameRate() for setting the sketch playback<br />

rate, noCursor() for hiding the cursor, <strong>and</strong> cursor() for setting the cursor’s icon.<br />

The rest of the entries are for accessing environmental properties—for example, focused<br />

gets the current focus state (true or false) of a sketch (whether the running sketch is the<br />

active application on your desktop); online accesses the sketch’s online status (whether<br />

the sketch is running in a browser—note that the applet can be on your local machine or<br />

a remote server for this property to be true); <strong>and</strong> screen gets information about the<br />

resolution of your monitor (e.g., screen.width gets the width of your screen).<br />

One somewhat confusing detail in this section is the use of the identical keywords<br />

frameRate() <strong>and</strong> frameRate. The first is a function call (you can always tell by the inclusion<br />

of the parentheses) for setting the sketch’s frame rate, <strong>and</strong> the second is a variable<br />

(property) for accessing the current frame rate.<br />

In general, environment properties are connected to what can be referred to as object singletons—objects<br />

representing the mouse, computer screen, <strong>Processing</strong> program, <strong>and</strong> so<br />

on—that are the only instance created from their respective class. For example, there may<br />

be a Mouse class defined in your operating system that describes the attributes <strong>and</strong> behavior<br />

of a mouse. To use the Mouse class, an object of the Mouse class is created. Since there<br />

is (usually) only one mouse connected to your computer, there is only ever one mouse<br />

object at any time—unlike, say, window objects, which are created every time you open a<br />

document. Thus, when you change an environmental variable, its effect is felt throughout<br />

the entire program.<br />

Data<br />

The Data section contains entries that represent the core data types within <strong>Processing</strong>, as<br />

well as utility functions that allow you to conveniently work with data (such as converting<br />

from one data type to another, manipulating strings, <strong>and</strong> transforming arrays).<br />

At the lowest level, the computer sees all data as bits (zeros <strong>and</strong> ones), <strong>and</strong> couldn’t care<br />

less what each bit st<strong>and</strong>s for. In contrast, we humans, with our limited internal calculating<br />

capabilities, require more complex signs (labels) than bitstrings to be able to remember<br />

<strong>and</strong> categorize stuff. Data types add logical meaning to the process of coding, allowing us<br />

to express ourselves through programming languages—in a form somewhere between<br />

pure bits <strong>and</strong> our natural language. For example, even though the statement<br />

String yourName = "Matilda";<br />

is not quite English, it does tell us that the literal name Matilda is being assigned to a variable<br />

called yourName that is of data type String. This is certainly easier to underst<strong>and</strong> than<br />

1101101110000111101001101001110110011001001100001, which is Matilda converted to

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

Saved successfully!

Ooh no, something went wrong!