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.

Next is an interactive example that illustrates this interpolation process as a simple geometric<br />

progression. The sketch (shown in Figure 7-27) plots a quadratic curve using two<br />

anchor points <strong>and</strong> a single control point, <strong>and</strong> interpolates between these three points.<br />

Technically, the area defined by the control <strong>and</strong> anchor points is called a convex hull. Each<br />

time you click within the example, another iteration occurs, dividing the previous segments<br />

in half <strong>and</strong> plotting the path, slowly approximating the curve.<br />

/* Interpolating a Bézier<br />

curve within a convex hull<br />

**************************<br />

Click the screen a couple of<br />

times to iteratively generate<br />

the curve*/<br />

int startingPoints = 3;<br />

// Uses Java's Point class<br />

Point[] bezier = new Point[startingPoints];<br />

void setup(){<br />

size(600, 400);<br />

background(255);<br />

smooth();<br />

// create external bezier<br />

bezier[0] = new Point(10, 390);<br />

bezier[1] = new Point(300, 10);<br />

bezier[2] = new Point(590, 390);<br />

// plot initial convex hull<br />

plot(bezier);<br />

}<br />

Point[] plotBezier(Point[] pts){<br />

Point[] path = new Point[pts.length+1];<br />

path[0] = pts[0];<br />

for (int i=1; i

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

Saved successfully!

Ooh no, something went wrong!