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.

works by defining the center point of the fan <strong>and</strong> then selecting the vertices in a clockwise<br />

fashion along the perimeter of the shape you want to triangulate. Once again, the trig<br />

functions come in h<strong>and</strong>y. Here’s an example sketch that triangulates any regular polygon,<br />

using TRIANGLE_FAN mode (see Figure 9-27):<br />

//TRIANGLE_FAN<br />

size(400, 400);<br />

smooth();<br />

strokeWeight(1.5);<br />

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

float angle = 0;<br />

float radius = 150;<br />

int pts = 8;<br />

int x = width/2;<br />

int y = height/2;<br />

// needs to rotate clockwise<br />

beginShape(TRIANGLE_FAN);<br />

vertex(x, y);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!