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 />

282<br />

I used p4 to its left, I chose to go back to the beginning of my curve, ensuring that p4 had<br />

a control point to its right. (I know this is confusing <strong>and</strong> not intuitive at all.) One other little<br />

trick that may make this more comprehensible is that if you copy the third through the<br />

eighth parameters of a curve() function call <strong>and</strong> paste them in another curve() call, then<br />

the curves will connect. You’ll still need to add a seventh <strong>and</strong> eighth parameter to this new<br />

curve. Look at these two lines:<br />

curve(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);<br />

curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);<br />

Notice how the third through eighth parameters in the first curve() call repeat as the first<br />

through the sixth parameters in the next curve() call. I still need to add the last two<br />

parameters to the second curve, which I do by continuing the cycle from p3 to p4 for the<br />

seventh <strong>and</strong> eighth parameters:<br />

curve(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);<br />

curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);<br />

Finally, there is one other cool function available to control the tension of the spline curve;<br />

it works similarly to how control points on a Bézier curve exaggerate or flatten a curve,<br />

depending upon where the h<strong>and</strong>les are located. Using curve(), you don’t literally drag any<br />

h<strong>and</strong>les or set extra control points off the curve. Instead, you simply pass a value to the<br />

curveTightness(value) function. The value can be negative or positive. In this next example<br />

(shown in Figure 7-31), I create a series of identical spline curves, with varying degrees<br />

of curve tightness, using the values -2, -1, 0, 1, <strong>and</strong> 2 as arguments in the<br />

curveTightness(value) function (please note that you need to use <strong>Processing</strong>’s noFill()<br />

function if you don’t want your curves filling in):<br />

// Catmull-Rom spline curve<br />

// Curve Tightness<br />

size(600, 400);<br />

background(0);<br />

stroke(255);<br />

strokeWeight(2);<br />

smooth();<br />

int curveWdth = 50;<br />

int cols = 5;<br />

int xPadding = (width-curveWdth*cols)/(cols+1);<br />

int x = xPadding;<br />

for (int i=-2; i

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

Saved successfully!

Ooh no, something went wrong!