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.

Creating a custom cube<br />

To begin to think about a cube, you need to think about the components of a cube. A<br />

cube can be thought of in a number of ways: as a group of points defining the cube’s vertices,<br />

sometimes referred to as a point cloud; as a wireframe, representing the lines connecting<br />

the cube’s vertices; or as a solid, composed of polygonal sides or faces. In a more<br />

advanced example, you might also look at different shading <strong>and</strong> surface material algorithms<br />

to create a photorealistically textured cube. This section will begin with the creation<br />

of a simple class that holds the three x, y, <strong>and</strong> z coordinates for each of the cube’s vertices.<br />

The class will be named Point3D.<br />

/*<br />

Extremely simple class to<br />

hold each 3D vertex<br />

*/<br />

class Point3D{<br />

float x, y, z;<br />

// constructors<br />

Point3D(){<br />

}<br />

Point3D(float x, float y, float z){<br />

this.x = x;<br />

this.y = y;<br />

this.z = z;<br />

}<br />

}<br />

I hope this class looks self-explanatory. I’m using the class simply to group the three component<br />

properties of each vertex. As a refresher, to create a Point3D object <strong>and</strong> then output<br />

its component properties, you’d write the following:<br />

void setup(){<br />

Point3D p1 = new Point3D(-50, -50, -50);<br />

println(p1.x + ", " + p1.y + ", " + p1.z);<br />

}<br />

/*<br />

Extremely simple class to<br />

hold each 3D vertex<br />

*/<br />

class Point3D{<br />

float x, y, z;<br />

// constructors<br />

Point3D(){<br />

}<br />

3D<br />

625<br />

13

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

Saved successfully!

Ooh no, something went wrong!