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.

its binary equivalent. I used some of the comm<strong>and</strong>s in this section of the API to generate<br />

the Matilda bitstring. Here’s the code I ran:<br />

int m = int(‘M’);<br />

int a = int(‘a’);<br />

int t = int(‘t’);<br />

int i = int(‘i’);<br />

int l = int(‘l’);<br />

int d = int(‘d’);<br />

println(binary(m)+binary(a)+binary(t)+binary(i)+ ➥<br />

binary(l)+binary(d)+binary(a));<br />

The five subsections of Data are as follows:<br />

Primitive<br />

Primitive<br />

Composite<br />

Conversion<br />

String Functions<br />

Array Functions<br />

Primitive includes data types used to store individual values—for example, int nodeCount<br />

= 6; or float speed = .5;. As discussed already, variables in <strong>Processing</strong> <strong>and</strong> Java need to<br />

be declared of a specific type. Types specify the kind of data a variable can hold <strong>and</strong> also<br />

the limit to the size of the value they can hold. Primitive variables are also assigned values<br />

directly. In the statement float speed = .5;, the real value .5 is literally assigned to the<br />

variable speed.<br />

There are also reference variables in <strong>Processing</strong> <strong>and</strong> Java, in which a variable is not<br />

assigned a direct value, but rather the address in memory to where the value is stored. This<br />

strange-sounding arrangement is also referred to as a pointer in other languages. Since<br />

objects, as well as arrays (which hold multiple values), are complex structures, it makes<br />

some sense to store a reference to the data, rather than the actual data.<br />

The <strong>Processing</strong> primitive data types are a subset of Java’s primitive data types. Java has a<br />

few more subtle variations on the main ones in <strong>Processing</strong> that most beginning coders can<br />

avoid. However, you are free to use Java’s extra data types in <strong>Processing</strong> if you’d like.<br />

Finally, there is a primitive data type in <strong>Processing</strong> that is not in Java: the color data type.<br />

This <strong>Processing</strong> type is really just an int type in disguise, used to deal specifically with<br />

color values. Appendix B includes detailed technical information about the inner workings<br />

of <strong>Processing</strong>’s color data type.<br />

Fortunately, actually using primitives in <strong>Processing</strong> is a lot simpler than trying to underst<strong>and</strong><br />

my theoretical, long-winded description of them. I go into greater depth about variables<br />

<strong>and</strong> data types in Chapter 3, <strong>and</strong> I also cover color in more detail toward the end of<br />

this chapter, as well as in Chapter 4.<br />

PROCESSING LANGUAGE API<br />

679<br />

A

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

Saved successfully!

Ooh no, something went wrong!