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

222<br />

The following sketch creates a concentric maze, but instead of using a more elegant rulebased<br />

algorithm, my cruder solution simply alters a vertical <strong>and</strong> horizontal stepping variable<br />

each iteration of the loop, beginning at the outer boundary. My implementation does<br />

allow you to have asymmetry with regard to the x- <strong>and</strong> y-axes, as well as use any display<br />

window size. I also utilize a few new functions in the loop that will require some clarification.<br />

Figure 6-36 shows the output of the code.<br />

/*<br />

Concentric Maze<br />

Ira Greenberg, November 25, 2005<br />

revised October 18, 2006<br />

*/<br />

size(400, 400);<br />

background(0);<br />

strokeWeight(1);<br />

stroke(255);<br />

smooth();<br />

float x = width-1;<br />

float y = height-1;<br />

float y2 = 0, x2 = 0;<br />

float h = 0, w = 0;<br />

//these values can be changed<br />

float wStep = 10.0;<br />

float hStep = 10.0;<br />

noFill();<br />

beginShape();<br />

vertex(x-w, y2+h);<br />

for (int i=min(width, height); i>min(width, height)/2; ➥<br />

i-=max(wStep, hStep)){<br />

vertex(x-w, y-h);<br />

vertex(x2+w, y-h);<br />

vertex(x2+w, y2+h);<br />

w+=wStep;<br />

vertex(x-w, y2+h);<br />

h+=hStep;<br />

}<br />

endShape();

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

Saved successfully!

Ooh no, something went wrong!