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.

Figure 13-6. Multiple Translations with pushMatrix()<br />

<strong>and</strong> popMatrix() example<br />

Notice how the pushMatrix() <strong>and</strong> popMatrix() functions surround the translate() <strong>and</strong><br />

box() calls. pushMatrix() must come before popMatrix(), <strong>and</strong> they need to work as a<br />

pair. The underlying math <strong>and</strong> theory behind these functions is not simple, but using them<br />

really is. You can even nest these function calls, as long as you have a popMatrix() for<br />

each pushMatrix(). The next example, shown in Figure 13-7, constructs a cube of cubes.<br />

The fill color is controlled by the counters in the three for loops. I also made the color<br />

translucent, in order to reveal the multicube structure.<br />

// Cubic Grid<br />

float boxSize = 40;<br />

float margin = boxSize*2;<br />

float depth = 400;<br />

color boxFill;<br />

void setup(){<br />

size(400, 400, P3D);<br />

noStroke();<br />

}<br />

void draw(){<br />

background(255);<br />

// center <strong>and</strong> spin grid<br />

translate(width/2, height/2, -depth/2);<br />

rotateY(frameCount*PI/60);<br />

rotateX(frameCount*PI/60);<br />

// build grid using multiple translations<br />

for (float i=-depth/2+margin; i

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

Saved successfully!

Ooh no, something went wrong!