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-26. Interactive Toroid sketch (polyhedron variation)<br />

If you haven’t yet, I suggest interacting with the toroid sketch. The four arrow keys <strong>and</strong> the<br />

keys A, S, Z, <strong>and</strong> X can all be pressed <strong>and</strong> held down. The W <strong>and</strong> H keys can only be<br />

pressed <strong>and</strong> released. When playing with the sketch, you might try to make some of the<br />

following forms: a bicycle inner tube, a monster truck inner tube, a picture frame, a<br />

sawed-off pyramid, a sphere, a shell, a star, a braid, or part of a phone cord. Toggling<br />

between shaded <strong>and</strong> wireframe view (using the W key) makes it easier to see how the<br />

geometry is changing.<br />

Here’s how to make a sphere: press <strong>and</strong> hold the A key until the form stops collapsing.<br />

Make sure that you press the W key to see the wireframe. To increase the size of the<br />

sphere, press <strong>and</strong> hold the X key. Obviously, this is not the most efficient way to generate<br />

a sphere, but it’s interesting to see its relationship to the toroid. A more efficient way to<br />

generate a sphere would be to create a 180-degree arc <strong>and</strong> then lathe it 360 degrees.<br />

This sketch brings together many of the features covered earlier in this chapter. The major<br />

challenge was combining the point coordinate data used to generate the initial polygon<br />

with the lathing of that data around the toroid. I used two separate arrays, vertices[] <strong>and</strong><br />

vertices2[], to enable me to combine the data. The initial polygon (to be lathed) was<br />

generated with the two lines of code used to plot a polygon in the xz plane:<br />

vertices[i].x = latheRadius + sin(radians(angle))*radius;<br />

vertices[i].z = cos(radians(angle))*radius;<br />

If I had plotted this initial polygon, it would have displayed only a horizontal line on the<br />

right side of the screen, since the y values are all 0 <strong>and</strong> the z dimension of the polygon<br />

can’t be seen in the xy plane.<br />

3D<br />

669<br />

13

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

Saved successfully!

Ooh no, something went wrong!