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

358<br />

Plotting shapes<br />

Figure 9-15. printMatrix() sketch<br />

Although the basic shape functions rect(), ellipse(), triangle(), <strong>and</strong> quad() offer<br />

some convenience, they are also pretty limited. <strong>Processing</strong> has a more general <strong>and</strong> versatile<br />

approach to shape creation that you’ve looked at before. Utilizing beginShape(),<br />

endShape(), <strong>and</strong> a series of vertex() comm<strong>and</strong>s, any shape can be created using<br />

<strong>Processing</strong>. These shapes can include combinations of both straight <strong>and</strong> curved sections.<br />

beginShape() also offers some advanced modes, allowing more complex polygonal structures<br />

to be created. You’ve used these functions before, so some of this will likely be<br />

review. I’ll begin by examining the default closed mode, which will generate a polygon (see<br />

Figure 9-16):<br />

//Octagon<br />

size(400, 400);<br />

background(255);<br />

smooth();<br />

int margin = 50;<br />

fill(0);<br />

stroke(127);<br />

strokeWeight(6);<br />

beginShape();<br />

vertex(3, height/2);<br />

vertex(margin, margin);

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

Saved successfully!

Ooh no, something went wrong!