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.

1. Generate a circle (actually a polygon) on the xy plane at the origin (0, 0).<br />

2. Displace the circle on the x-axis the distance of the toroid radius.<br />

3. Copy (lathe) the circle elliptically around the y-axis, maintaining the toroid radius<br />

distance from the origin.<br />

Toroids have a ring thickness, which relates to the initial diameter of the lathed circle, <strong>and</strong><br />

an inner hole diameter based on the distance of the lathed circle from the origin. The initial<br />

circle, which you’ll be lathing with, will actually be a polygon with a lot of points (like<br />

in the preceding cylinder example). Finally, the lathing will be controlled by a segment<br />

level, which determines how many copies of the circle are rotated around the y-axis. The<br />

lathe segments will be evenly spaced, <strong>and</strong> will determine the smoothness of the toroid.<br />

The really cool thing is that you can easily control all these properties in real time, interactively<br />

revealing a wide range of interesting 3D forms based on your initial algorithm. The<br />

following sketch includes a bunch of key comm<strong>and</strong>s, which are listed at the top of the program<br />

as a code comment. The sketch requires the Point3D class, but not the Cube class.<br />

/* Interactive Toroid<br />

Point3D class required<br />

****************************************<br />

key comm<strong>and</strong> controls<br />

******************<br />

UP arrow key pts++;<br />

DOWN arrow key pts--;<br />

LEFT arrow key segments--;<br />

RIGHT arrow key segments++;<br />

'a' key toroid radius--;<br />

's' key toroid radius++;<br />

'z' key initial polygon radius--;<br />

'x' key initial polygon radius++;<br />

'w' key toggle wireframe/solid shading<br />

'h' key toggle sphere/helix<br />

****************************************/<br />

//ellipse (shape to lathe)<br />

int pts = 40;<br />

float angle = 0;<br />

float radius = 40.0;<br />

// lathe segments<br />

int segments = 60;<br />

float latheAngle = 0;<br />

float latheRadius = 100.0;<br />

//vertices<br />

Point3D vertices[], vertices2[];<br />

// for shaded or wireframe rendering<br />

boolean isWireFrame = false;<br />

// for optional helix<br />

boolean isHelix = false;<br />

float helixOffset = 5.0;<br />

3D<br />

663<br />

13

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

Saved successfully!

Ooh no, something went wrong!