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

70<br />

Figure 3-2. Completed stepped radial gradient<br />

I begin the program with my st<strong>and</strong>ard “about the program” comments. Then I declare<br />

some global variables at the top of the program. Global, as opposed to local, means that<br />

the variables will be available from any place within the program. Later, when I cover functions,<br />

I’ll discuss this concept, called scope, further. You’ll notice I declared all the variables<br />

as type int. The line int gradientWidth, gradientHeight; declares both gradientWidth<br />

<strong>and</strong> gradientHeight variables as type int in one line. When declaring <strong>and</strong> initializing variables,<br />

you can put them on individual lines or bunch them together. For example, the<br />

following line is perfectly legal:<br />

int var1 = 3, var2 = 5, var3 = 6, var4 = 0;<br />

I declare four variables of type int, while also initializing them with initial values.<br />

After declaring variables, I set the size properties <strong>and</strong> background color of the sketch<br />

window:<br />

size(200,200);<br />

background(0);<br />

You might recognize these as function calls, in which dimensions (width <strong>and</strong> height) <strong>and</strong><br />

color arguments are passed to the respective <strong>Processing</strong> functions. These functions are<br />

built into the <strong>Processing</strong> language, which is why you don’t see the functions defined in the<br />

program anywhere. After you set the sketch window dimensions using the size(200, 200)<br />

comm<strong>and</strong>, you can then retrieve the sketch window size using <strong>Processing</strong>’s built-in global<br />

properties: width <strong>and</strong> height. You’ll notice these words turn a reddish color in the editor<br />

when you type them in, letting you know they are built-in properties in <strong>Processing</strong>.

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

Saved successfully!

Ooh no, something went wrong!