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.

Figure 6-39. Create 3 Triangles sketch<br />

Polygons <strong>and</strong> patterns<br />

Now that you have a basic underst<strong>and</strong>ing about how the trig functions can be used to<br />

identify a point on a circle, you can exploit that knowledge to generate any regular polygon.<br />

(Even if you don’t yet fully grasp—or even care—how the trig functions work, you<br />

can still use them. In fact, through using them, you’ll get a better underst<strong>and</strong>ing of how<br />

they work than through reading about them). The following example incorporates the<br />

beginShape() <strong>and</strong> endShape(CLOSE) functions in a basic polygon-creation algorithm (the<br />

output is shown in Figure 6-40):<br />

/*<br />

Poly Maker<br />

Ira Greenberg, November 26, 2005<br />

revised October 18, 2006<br />

*/<br />

void setup(){<br />

size(400, 400);<br />

background(0);<br />

smooth();<br />

noFill();<br />

makePoly(width/2, height/2, 9, 150, 255, 8, MITER);<br />

}<br />

void makePoly(int x, int y, int points, float radius, ➥<br />

int strokeCol, float strokeWt, int strokeJn){<br />

float px=0, py=0;<br />

float angle = 0;<br />

stroke(strokeCol);<br />

strokeJoin(strokeJn);<br />

strokeWeight(strokeWt);<br />

beginShape();<br />

LINES<br />

229<br />

6

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

Saved successfully!

Ooh no, something went wrong!