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

410<br />

// Transformation Matrix<br />

printMatrix();<br />

pushMatrix();<br />

translate(50, 50);<br />

rotate(PI);<br />

scale(.5);<br />

printMatrix();<br />

popMatrix();<br />

printMatrix();<br />

If you look at the output, you’ll see that the transformation matrix output is the same<br />

before <strong>and</strong> after the pushMatrix()/popMatrix() calls. Using pushMatrix() <strong>and</strong><br />

popMatrix(), I was able to localize the transformation so that the transformation state<br />

isn’t changed for all future calls. Returning to the earlier Fade-Spin example, I used the<br />

push <strong>and</strong> pop calls to do precisely the same thing. Try commenting out the<br />

pushMatrix()/popMatrix() calls to see what happens. To learn some more about transformations,<br />

check out www.developer.com/net/vb/article.php/626051#_Introduction.<br />

Finally, the Fade-Spin example was procedurally a little dense, as I used for loops to initialize<br />

<strong>and</strong> increment a bunch of values. Also, you’ll notice that sometimes I initialized the<br />

loop values as type int <strong>and</strong> other times as type float. If you specify a variable as type int<br />

<strong>and</strong> then try to increment it with a non-integer value, you’ll get unexpected results due to<br />

rounding, which can drastically change a sketch. Look at the values in this example:<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!