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.

easy. The benefit of internally recording the coordinate data is that the data can be plotted<br />

based on different drawing algorithms. Using different mode arguments within the<br />

beginShape() <strong>and</strong> endShape() functions, <strong>Processing</strong> can use the same vertex() data to<br />

draw different types of geometry.<br />

As a little example of how this internal recording process works, the following sketch<br />

(shown in Figure 6-32) re-creates some of the functionality of vertex(), using the point()<br />

<strong>and</strong> line() functions already covered. Although this may seem like an exercise in futility, I<br />

think it is helpful to have a sense of what’s happening internally, before you rely on these<br />

higher-level comm<strong>and</strong>s. In addition, you’ll see that by going a little lower level, other interesting<br />

creative possibilities arise. Afterward, we’ll look at similar functionality, the easy way.<br />

/*<br />

Point Recorder/Plotter<br />

Ira Greenberg, November 23, 2005<br />

*/<br />

void setup(){<br />

size(300, 300);<br />

background(0);<br />

// create arrays to hold x, y coords<br />

float[]x = new float[4];<br />

float[]y = new float[4];<br />

// create a convenient 2 dimensional<br />

// array to hold x, y arrays<br />

float[][]xy = {x, y};<br />

//record points<br />

//x positions<br />

xy[0][0] = 50;<br />

xy[0][1] = 250;<br />

xy[0][2] = 250;<br />

xy[0][3] = 50;<br />

//y positions<br />

xy[1][0] = 50;<br />

xy[1][1] = 50;<br />

xy[1][2] = 250;<br />

xy[1][3] = 250;<br />

// call plotting function<br />

makeRect(xy);<br />

}<br />

void makeRect(float[][]pts){<br />

stroke(255);<br />

smooth();<br />

LINES<br />

211<br />

6

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

Saved successfully!

Ooh no, something went wrong!