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.

Figure 9-21. R<strong>and</strong>om Triangles sketch (TRIANGLES mode)<br />

Although you could relatively easily write your own function to pull this sort of thing off,<br />

it is still convenient having this option. It would be a good exercise to try to re-create the<br />

functionality of the beginShape(TRIANGLES) mode using the triangle() function or<br />

the no-argument version of beginShape().<br />

Notice the extra argument in the comm<strong>and</strong> fill(r<strong>and</strong>om(225, 255), 150);, after the<br />

closed parentheses of the r<strong>and</strong>om call. This optional second argument allows you to control<br />

the alpha, or transparency, of the grayscale fill. The value range is from 0 to 255<br />

(0 being transparent <strong>and</strong> 255 being completely opaque). If you don’t specify an argument,<br />

the default value is 255. The stroke() <strong>and</strong> fill() comm<strong>and</strong>s each allow you to specify<br />

one, two, three, or four arguments. In the next chapter, I’ll discuss color <strong>and</strong> imaging, <strong>and</strong><br />

concepts like alpha in greater detail.<br />

beginShape(QUADS) mode works similarly to TRIANGLE mode, except that shapes are<br />

closed in groups of four vertex() calls instead of three. In this next example, I generate<br />

r<strong>and</strong>om quads, bounded within a rectangular region, forming a sort of shape texture (see<br />

Figure 9-22).<br />

//R<strong>and</strong>om Bounded Quads<br />

size (250, 250);<br />

background(255);<br />

smooth();<br />

int[]boundinBox = {50, 50, 150, 150};<br />

fill(0);<br />

SHAPES<br />

369<br />

9

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

Saved successfully!

Ooh no, something went wrong!