06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

234 <strong>Learning</strong> <strong>Processing</strong><br />

We also have the option of creating more than one shape, for example, in a loop, as shown in Figure 14.7 .<br />

stroke(0);<br />

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

beginShape();<br />

fill(175);<br />

vertex(i*20,10-i);<br />

vertex(i*20 + 15,10 + i);<br />

vertex(i*20 + 15,180 + i);<br />

vertex(i*20,180-i);<br />

endShape(CLOSE);<br />

}<br />

You can also add an argument <strong>to</strong> beginShape( ) specifying exactly what type of shape you want <strong>to</strong><br />

make. Th is is particularly useful if you want <strong>to</strong> make more than one polygon. For example, if you<br />

create six vertex points, there is no way for <strong>Processing</strong> <strong>to</strong> know that you really want <strong>to</strong> draw two<br />

triangles (as opposed <strong>to</strong> one hexagon) unless you say beginShape(TRIANGLES) . If you do not want<br />

<strong>to</strong> make a polygon at all, but want <strong>to</strong> draw points or lines, you can by saying beginShape(POINTS) or<br />

beginShape(LINES) . See Figure 14.8 .<br />

stroke(0);<br />

beginShape(LINES);<br />

for (int i = 10; i < width; i + = 20) {<br />

vertex(i,10);<br />

vertex(i,height–10);<br />

}<br />

endShape();<br />

Note that LINES is meant for drawing a series of individual lines, not a continous loop. For a continuous<br />

loop, do not use any argument. Instead, simply specify all the vertex points you need and include noFill( ) .<br />

See Figure 14.9 .<br />

noFill();<br />

stroke(0);<br />

beginShape();<br />

for (int i = 10; i < width; i + = 20) {<br />

vertex(i,10);<br />

vertex(i,height–10);<br />

}<br />

endShape();<br />

fi g. 14.7<br />

fi g. 14.8<br />

fi g. 14.9<br />

Th e full list of possible arguments for beginShape( ) is available in the <strong>Processing</strong> reference<br />

http://processing.org/reference/beginShape_.html<br />

POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS,<br />

QUAD_STRIP

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

Saved successfully!

Ooh no, something went wrong!