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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

698<br />

Attributes<br />

The Attributes section includes seven functions:<br />

strokeWeight()<br />

smooth()<br />

strokeJoin()<br />

noSmooth()<br />

ellipseMode()<br />

rectMode()<br />

strokeCap()<br />

Stroke is the term used for a line in computer graphics. The functions strokeWeight(),<br />

strokeCap(), <strong>and</strong> strokeJoin() respectively control the thickness (or weight) of lines,<br />

how the lines end (rounded, square, or extended caps), <strong>and</strong> how the lines come together<br />

at corners (mitered, beveled, or rounded). These last two line attributes are details we<br />

tend not to focus on until we see a problem with our output, <strong>and</strong> then of course we<br />

obsess about them.<br />

smooth() <strong>and</strong> noSmooth() control anti-aliasing. Anti-aliasing is not a political position, but<br />

a way to smooth jaggies along curved <strong>and</strong> diagonal edges. Anti-aliasing makes things look<br />

smoother, but can slow down rendering some. Please note that the smooth <strong>and</strong> stroke<br />

attribute functions do not (as of this writing) work consistently in all three supported renderers;<br />

nor do they fail consistently—the strokeWeight() attribute fails silently in P3D<br />

mode (it just won’t do anything), but the other functions will generate a compiler error.<br />

For more details, please see the corresponding section of the API (www.processing.org/<br />

reference/strokeWeight_.html).<br />

Vertex<br />

The Vertex section includes seven functions that allow you to do some pretty amazing<br />

things. A vertex is just a point. Vertices (the plural form of vertex) make up lines, which<br />

make up polygons (usually triangles or quadrangles), which make up more complex geometry.<br />

In fact, most complex 3D scenes are usually just a bunch of triangles <strong>and</strong> quadrangles.<br />

To create a vertex in <strong>Processing</strong>, you use the vertex() function. Combining a series of<br />

vertex() comm<strong>and</strong>s allow you to create lines <strong>and</strong> shapes (both 2D <strong>and</strong> 3D). Additionally,<br />

you can use the related functions bezierVertex() <strong>and</strong> curveVertex() to specify curves,<br />

<strong>and</strong> you can also combine the three comm<strong>and</strong>s.<br />

The vertex functions need to be called between the functions beginShape() <strong>and</strong><br />

endShape(). These two functions work by first internally recording the coordinates specified<br />

by the nested vertex calls, <strong>and</strong> then plotting the coordinates. They also control how<br />

the vertices are connected by passing arguments to the two calls. For example, here’s<br />

some code to generate a closed regular polygon:

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

Saved successfully!

Ooh no, something went wrong!