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

368<br />

Figure 9-20. Hybrid Shape 2 sketch<br />

This sketch makes a good gear shape. If you change the value of the sides variable in the<br />

example, the shape scales nicely. I think it would be a good exercise to try to “functionalize”<br />

this last example. In other words, try sticking the main drawing routine in a function<br />

with a bunch of parameters, as I did with the polygon <strong>and</strong> sprocket examples. Besides<br />

curveVertex(), you can also use bezierVertex() in conjunction with regular vertex()<br />

calls, but I’ll also leave that for you to try on your own.<br />

The other shape modes<br />

There are a number of additional shape modes. Many of these are more applicable to 3D<br />

than 2D, for creating a skin or polygonal mesh around a 3D form. In the 3D chapters, you’ll<br />

learn how to plot some 3D forms. For now, I’m just going to give a brief overview of what<br />

the other modes do. The first two you’ll look at, TRIANGLES <strong>and</strong> QUADS, don’t form a contiguous<br />

mesh, but rather simply create individual triangles <strong>and</strong> quadrangles from lists of<br />

coordinates. In the next example, I’ll generate 90 triangles using a for loop <strong>and</strong> the<br />

TRIANGLES mode (see Figure 9-21):<br />

//R<strong>and</strong>om Triangles<br />

size (500, 500);<br />

background(255);<br />

smooth();<br />

beginShape(TRIANGLES);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!