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

278<br />

Figure 7-28. Cubic Bézier curve<br />

Figure 7-28 shows an approximation of a Bézier curve based on a third-degree (cubic)<br />

polynomial, which I discussed earlier in the chapter. These are the most commonly used<br />

equations for calculating curves in computer graphics; although lower- <strong>and</strong> higher-degree<br />

polynomials can also be used. Wikipedia provides some excellent animations illustrating<br />

how polynomials generate Bézier curves. I was really tempted to recode these in<br />

<strong>Processing</strong>, but I think I’ll leave that for you. You can find the animations at<br />

http://en.wikipedia.org/wiki/Bezier_curve.<br />

Bézier curves can also be strung together to form longer continuous curves. The following<br />

example (shown in Figure 7-29) does just that:<br />

// Bézier path<br />

size(500, 500);<br />

background(255);<br />

rectMode(CENTER);<br />

bezier(150, 100, 200, 50, 300, 50, 350, 100);<br />

line(150, 100, 200, 50);<br />

rect(150, 100, 10, 10);<br />

ellipse(200, 50, 10, 10);<br />

line(350, 100, 300, 50);<br />

rect(350, 100, 10, 10);<br />

ellipse(300, 50, 10, 10);

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

Saved successfully!

Ooh no, something went wrong!