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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

298<br />

The nastiness with the spline curves is in figuring out the order of the control points. It’s<br />

important to remember that each point needs a control point on either side of itself. In<br />

the block of code for the outer curve:<br />

curve(cx[3], cy[3], cx[0], cy[0], cx[1], cy[1], cx[2], cy[2]);<br />

curve(cx[0], cy[0], cx[1], cy[1], cx[2], cy[2], cx[3], cy[3]);<br />

curve(cx[1], cy[1], cx[2], cy[2], cx[3], cy[3], cx[0], cy[0]);<br />

curve(cx[2], cy[2], cx[3], cy[3], cx[0], cy[0], cx[1], cy[1]);<br />

notice the order of the indices in the array brackets:<br />

3, 0, 1, 2<br />

0, 1, 2, 3<br />

1, 2, 3, 0<br />

2, 3, 0, 1<br />

Each succeeding row begins with the second through the fourth values, <strong>and</strong> then the next<br />

logical value is added. Once you get to the highest value (in this case, 3), you go back to 0.<br />

I recommend messing with this order to see how it affects the curve.<br />

The curveEllipse() function adds flexibility to the curve-creation process. You generally<br />

want to structure your code to build in as much flexibility as possible. Functions <strong>and</strong><br />

eventually objects offer this possibility. Notice that the curveVertex() calls in the<br />

curveEllipse() function require some conditional statements within the for loop, ensuring<br />

that the correct ordering of indices is followed, as discussed earlier:<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!