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

210<br />

The vertex() function takes either two or three arguments (of type int or float), for<br />

coordinates in 2D or 3D, respectively:<br />

vertex(x, y)<br />

vertex(x, y, z)<br />

This chapter will only look at vertices in two dimensions; in later chapters, you’ll plot forms<br />

in 3D. Here’s a really simple example of the vertex() function in action, using the POINTS<br />

mode (see Figure 6-31):<br />

size(300, 300);<br />

background(0);<br />

stroke(255);<br />

strokeWeight(5);<br />

beginShape(POINTS);<br />

vertex(50, 50);<br />

vertex(width-50, 50);<br />

vertex(width-50, height-50);<br />

vertex(50, height-50);<br />

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

endShape();<br />

Figure 6-31. POINTS mode sketch example<br />

This is not a very impressive example, <strong>and</strong> I believe it shows that using the vertex() function<br />

to generate points doesn’t offer much advantage over using the good old point()<br />

function covered earlier. You’ll notice that the vertex() calls occur between the<br />

beginShape() <strong>and</strong> endShape() function calls. In a sense, the beginShape() function begins<br />

recording drawing instructions, <strong>and</strong> the endShape() function stops recording <strong>and</strong> then<br />

renders the drawing data to the screen. As usual, <strong>Processing</strong> makes this stuff look incredibly

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

Saved successfully!

Ooh no, something went wrong!