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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

212<br />

for (int i=0; i0){<br />

line(pts[0][i], pts[1][i], pts[0][i-1], pts[1][i-1]);<br />

}<br />

if (i== pts[0].length-1){<br />

line(pts[0][i], pts[1][i], pts[0][0], pts[1][0]);<br />

}<br />

}<br />

}<br />

Figure 6-32. Point Recorder/Plotter sketch<br />

Hopefully some of this looks familiar. You’ve already used for loops to run through the<br />

indices of an array, as well as created your own custom functions to modularize a process.<br />

This example also introduces a new variation on an older theme—2D arrays—<strong>and</strong> also<br />

utilizes another simple rendering option, the smooth() function. However, before I discuss<br />

either of these new structures, let’s look at what’s happening in this sketch.<br />

Within setup(), I created a couple of arrays <strong>and</strong> populated them with coordinate data<br />

describing the vertices of a square. Obviously, if you were going to use a vertex coordinate<br />

recording process like this for real, you would not hard-code in the coordinate values,<br />

which if you remember are called magic numbers <strong>and</strong> are generally to be avoided.<br />

However, to keep things simple I broke my own rule. After I fill the array with these values,

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

Saved successfully!

Ooh no, something went wrong!