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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

168<br />

//simple Cube class, based on Quads<br />

class Cube {<br />

//properties<br />

int w, h, d;<br />

int shiftX, shiftY, shiftZ;<br />

//constructor<br />

Cube(int w, int h, int d, int shiftX, int shiftY, int shiftZ){<br />

this.w = w;<br />

this.h = h;<br />

this.d = d;<br />

this.shiftX = shiftX;<br />

this.shiftY = shiftY;<br />

this.shiftZ = shiftZ;<br />

}<br />

/*main cube drawing method, which looks<br />

more confusing than it really is. It's<br />

just a bunch of rectangles drawn for<br />

each cube face*/<br />

void drawCube(){<br />

beginShape(QUADS);<br />

//front face<br />

vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ);<br />

vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);<br />

vertex(w + shiftX, h + shiftY, -d/2 + shiftZ);<br />

vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ);<br />

//back face<br />

vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ);<br />

vertex(w + shiftX, -h/2 + shiftY, d + shiftZ);<br />

vertex(w + shiftX, h + shiftY, d + shiftZ);<br />

vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);<br />

//left face<br />

vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ);<br />

vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ);<br />

vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);<br />

vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ);<br />

//right face<br />

vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);<br />

vertex(w + shiftX, -h/2 + shiftY, d + shiftZ);<br />

vertex(w + shiftX, h + shiftY, d + shiftZ);<br />

vertex(w + shiftX, h + shiftY, -d/2 + shiftZ);

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

Saved successfully!

Ooh no, something went wrong!