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

226<br />

Figure 6-37. Maze Tile 1 sketch<br />

Line loops<br />

It’s also possible to close a line strip, turning it into a line loop. The endShape() function<br />

has an optional CLOSE argument that closes the strip. Since the CLOSE mode generates<br />

complete shapes, I thought it would be fun to generate some polygonal geometry; <strong>and</strong><br />

the best (<strong>and</strong> easiest) way to do that is to use a little trigonometry. Here’s a very simple<br />

sketch that generates a triangle (see Figure 6-38). (Yes, I know <strong>Processing</strong> comes with a<br />

triangle() function; but it’s actually a lot easier to use a little trig to calculate the vertices<br />

of a triangle rather than having to explicitly set the vertices. Also, once you have the<br />

triangle code, you can easily modify it to generate any regular polygon—which I’ll show<br />

you how to do shortly.)

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

Saved successfully!

Ooh no, something went wrong!