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.

cx = width/2;<br />

cy = height/2;<br />

background(255);<br />

// collect points to plot shape<br />

for (int i = 0; i< sides; i++){<br />

px = cx+cos(radians(angle))*radius;<br />

py = cy+sin(radians(angle))*radius;<br />

ptsX[i] = px;<br />

ptsY[i] = py;<br />

angle+=360/sides;<br />

}<br />

// call custom function<br />

drawShape();<br />

}<br />

//custom function plots a polygon<br />

void drawShape(){<br />

noFill();<br />

for (int i = 0; i< sides; i++){<br />

// if last point, connect to initial point to close shape<br />

if (i == sides-1){<br />

line(ptsX[i], ptsY[i], ptsX[0], ptsY[0]);<br />

}<br />

else {<br />

line(ptsX[i], ptsY[i], ptsX[i+1], ptsY[i+1]);<br />

}<br />

}<br />

}<br />

Figure 5-12. Screen capture of the Polygon sketch<br />

THE PROCESSING ENVIRONMENT<br />

163<br />

5

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

Saved successfully!

Ooh no, something went wrong!