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.

concentric circles<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, w-50, h-50, 0, PI*2);<br />

noFill();<br />

arc(x, y, w, h, 0, TWO_PI);<br />

Figure 7-22. Creating circles with arc()<br />

The arc() function’s first four arguments are identical to ellipse()’s arguments: x, y,<br />

width, <strong>and</strong> height. You can also specify an ellipseMode() when using arc() to control<br />

from what point the arc is drawn; the default mode is CENTER. The arc() function’s last<br />

two arguments are the start <strong>and</strong> end angles of the arc’s rotation, specified in radians. If<br />

you prefer to work in degrees, just convert the degrees to radians, using the<br />

radians(angle) function. You’ll notice in my examples that I used PI as my value of rotation.<br />

PI, in radians, specifies 180 degree rotation around an ellipse. PI*2, in radians, gives<br />

one complete rotation (360 degrees). <strong>Processing</strong> actually has a constant for this as well:<br />

TWO_PI, which I used in the second arc() statement.<br />

Although arc() is easy to use, it is somewhat lacking as a general-purpose curve tool. For<br />

example, to create a continuous curve path, it’s a little annoying trying to get a series of<br />

arcs to line up. I’ll look at other <strong>Processing</strong> curve functions that do a better job with that.<br />

One cool thing you can do with arc() is make wedge shapes. A not-so-exciting application<br />

of this would be your st<strong>and</strong>ard pie chart. Here’s a simple example (shown in Figure 7-23):<br />

CURVES<br />

269<br />

7

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

Saved successfully!

Ooh no, something went wrong!