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.

ect(103, 120, 130, 100);<br />

rectMode(CENTER);<br />

rect(103, 120, 130, 100);<br />

rectMode(CORNERS);<br />

rect(233, 220, 363, 320);<br />

}<br />

Figure 9-5. Arcs with Bounding Boxes sketch<br />

In this last sketch, I used the ellipse() example code <strong>and</strong> simply switched the ellipse<br />

keyword with arc, adding the two additional required start <strong>and</strong> end angle arguments. (The<br />

angle arguments need to be specified in radians, <strong>and</strong> the value of PI in radians is equivalent<br />

to 180 degrees, or 1/2 rotation around an ellipse.) I was able to use the ellipse()<br />

example source code, as arc() shares the same four initial arguments as ellipse() <strong>and</strong><br />

also uses the ellipseMode() function to specify its drawing mode. Really, an arc <strong>and</strong> an<br />

ellipse are related, as both are internally implemented the same way using cosine <strong>and</strong> sine<br />

functions. Later in the chapter, I’ll show you how to create an ellipse in <strong>Processing</strong> using<br />

some trig functions. As I demonstrated in Chapter 7, if you use 0 <strong>and</strong> TWO_PI as your two<br />

angle arguments when calling arc(), you’ll get an ellipse. I leave that for you to try on your<br />

own, if you missed it earlier. Next is an example that uses <strong>Processing</strong>’s triangle() function<br />

(see Figure 9-6):<br />

//Triangle<br />

Point[]p = new Point[3];<br />

void setup(){<br />

size(400, 400);<br />

background(190);<br />

p[0] = new Point(2, height-2);<br />

p[1] = new Point(width-2, height-2);<br />

p[2] = new Point(width/2, 2);<br />

SHAPES<br />

345<br />

9

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

Saved successfully!

Ooh no, something went wrong!