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

268<br />

arc()<br />

An arc is a curve segment of the circumference of a circle. The arc() function allows you<br />

to draw a curve segment by specifying the x <strong>and</strong> y position of the center of the circle, the<br />

width <strong>and</strong> height of the circle, <strong>and</strong> the beginning <strong>and</strong> ending angles (in radians) describing<br />

the arc rotation. It is helpful to remember that 2 * pi equals a full rotation around a circle.<br />

In the next sketch (shown in Figure 7-21) I create two arcs, each rotating halfway around<br />

the circle. The first arc begins at 0 <strong>and</strong> goes to pi, <strong>and</strong> the second begins at pi <strong>and</strong> ends at<br />

2 * pi (please note that pi is written as PI in <strong>Processing</strong>):<br />

//concave/convex curve<br />

size(200, 200);<br />

background(255);<br />

int x = width/2, y = height/2;<br />

int w = 100, h = 100;<br />

strokeWeight(4);<br />

smooth();<br />

fill(0);<br />

arc(x, y-h/2, w, h, 0, PI);<br />

noFill();<br />

arc(x, y+h/2, w, h, PI, PI*2);<br />

Figure 7-21. Using <strong>Processing</strong>’s arc() function<br />

The arc() function is easier to use than it looks. Because it requires six arguments, two of<br />

which are angles, it can seem overly complicated—but it really isn’t. It helps to think of the<br />

arc() function as a partial ellipse() function. In fact, if you really want to, you can use<br />

arc() in place of ellipse(). arc() also has both a fill <strong>and</strong> a stroke option, just like<br />

ellipse(). Here’s a simple modification to the program that creates two concentric circles<br />

using arc(), as shown in Figure 7-22:

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

Saved successfully!

Ooh no, something went wrong!