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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 13-8. Two Rotating Custom Cubes sketch<br />

I made the cubes translucent in this example (by lowering the fill color alpha to below<br />

255) so that you can see the inner cube. Notice how the two create() method calls automatically<br />

invoke the correct version of the method, based on the argument passed to the<br />

method.<br />

I created another example using the Cube class that’s a little more interesting, <strong>and</strong> of<br />

course a little more complicated. The sketch includes a bunch of small rotating, moving<br />

cubes within a larger rotating cube (see Figure 3-9). When the inner cubes hit the boundaries<br />

of the outer cube, they reverse direction. In addition, the cubes are all connected by<br />

a line. There’s actually nothing in this sketch that you haven’t already looked at. However,<br />

thinking in 3D space is definitely more confusing than in 2D. Again, I didn’t bother repeating<br />

the code from the updated Cube or Point3D classes; just remember to include both<br />

classes beneath the following code or in their own tabs.<br />

// Cubes Contained Within a Cube<br />

Cube stage; // external large cube<br />

int cubies = 50;<br />

Cube[]c = new Cube[cubies]; // internal little cubes<br />

color[][]quadBG = new color[cubies][6];<br />

// controls cubie's movement<br />

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

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

float[]z = new float[cubies];<br />

float[]xSpeed = new float[cubies];<br />

float[]ySpeed = new float[cubies];<br />

float[]zSpeed = new float[cubies];<br />

3D<br />

631<br />

13

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

Saved successfully!

Ooh no, something went wrong!