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

200<br />

Joining lines<br />

In the previous example, I also used a conditional statement to keep looping through the<br />

caps arrays. Since each end cap was output three times, I needed to keep resetting<br />

the array counter back to 0, which is exactly what the conditional statement does:<br />

if (j>2){<br />

j=0;<br />

}<br />

The next sketch, shown in Figure 6-25, illustrates the joining implications of the different<br />

end caps. In addition, the sketch implements a column layout algorithm, with simple<br />

padding between the corresponding cells. Try changing the value of the strokeWeight()<br />

argument as well as the shapes <strong>and</strong> padding variables to see what happens.<br />

/*<br />

Auto Layout<br />

Ira Greenberg, November 21, 2005<br />

*/<br />

size(500, 300);<br />

background(255);<br />

int[]caps = {ROUND, PROJECT, SQUARE};<br />

strokeWeight(20);<br />

int shapes = 3;<br />

int padding = 200;<br />

float w = (width-padding)/shapes;<br />

float h = w;<br />

float colSpan = (width-shapes*w)/(shapes+1);<br />

float x = colSpan;<br />

float y = height/2-h/2;<br />

for (int i=0, j=0; i2) j=0;<br />

line(x, y, x+w, y);<br />

line(x+w, y, x+w, y+h);<br />

line(x, y+h, x+w, y+h);<br />

line(x, y+h, x, y);<br />

x+=w+colSpan;<br />

}

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

Saved successfully!

Ooh no, something went wrong!