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.

The first example I’ll look at simply rotates a rectangle, which is coded procedurally. In the<br />

second example, I’ll reuse the Cube <strong>and</strong> Point3D classes to rotate a cube. Here’s the code<br />

for the first example (shown in Figure 13-11):<br />

// Custom Rotation of a Rectangle Around the X-, Y-, <strong>and</strong> Z-Axes<br />

// rectangle's vertices before rotation<br />

float[][]originalVertices = new float[4][3];<br />

// rectangle's vertices after rotation<br />

float[][]transformedVertices = new float[4][3];<br />

// control rectangle rotations<br />

float angleX, angleY, angleZ;<br />

void setup(){<br />

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

/* generate initial rectangle coordinate data<br />

filling originalVertices array */<br />

// creates rectangle parallel to window<br />

float angle = 45;<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!