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

274<br />

Figure 7-26. Bézier curve plot showing anchor<br />

<strong>and</strong> control points<br />

I utilized Java’s Point class in the example as a simple data structure. The Point class is not<br />

part of the <strong>Processing</strong> API, but I find it h<strong>and</strong>y to use because it provides direct access to an<br />

x <strong>and</strong> a y property, which I used to help keep track of the different anchor <strong>and</strong> control<br />

points. You can create a new Point object by simply writing Point pt1 = new Point(150,<br />

300);. The two arguments you pass, 150 <strong>and</strong> 300, will be the values of the x <strong>and</strong> y properties,<br />

respectively. So, to access the x <strong>and</strong> y values, I just write pt1.x <strong>and</strong> pt1.y. The rest of<br />

the code in the sketch is stuff you’ve seen numerous times before in earlier examples (<strong>and</strong><br />

will see a lot more of).<br />

If you’ve ever used a pen tool in a graphics application like Illustrator, Photoshop, or<br />

FreeH<strong>and</strong> (<strong>and</strong> I assume most of you have), then you’ve experienced Bézier curves, <strong>and</strong><br />

maybe you’ve even messed directly with their control points. Bézier curves are named<br />

after Pierre Bézier, a French mathematician <strong>and</strong> engineer who worked for the car manufacturer<br />

Renault. To learn more about Bézier <strong>and</strong> his curve, check out http://cg.scs.<br />

carleton.ca/~luc/bezier.html.<br />

There is a dynamic tension in a Bézier curve, determined by the placement of the control<br />

points (the small ellipse h<strong>and</strong>les in the example) <strong>and</strong> their relative position to the anchor<br />

points (the small squares at ends of curve). You’ll notice in the example that the curve<br />

seems to bend toward the control points. The situation is actually a little more complicated<br />

than that. The extra lines I rendered between the control points <strong>and</strong> the anchor<br />

points represent the slopes of the curves at the anchor points (also known as tangent<br />

lines). Slope is the change in y over the change in x (the rise over the run). Finding slopes<br />

of curves is a little tricky, since the curves are constantly changing, unlike straight lines, in<br />

which the slope is constant. On curves, you can take slope readings at distinct points. For<br />

a more generalized approach to solving for the slope of a curve, you need basic calculus—<br />

so I’ll stop there. In a sense, the Bézier curve between the two anchor points is calculated<br />

by blending, or interpolating, the two slopes of the curve at the anchor points, as well as<br />

factoring in the distance between the anchor <strong>and</strong> control points.

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

Saved successfully!

Ooh no, something went wrong!