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.

ect(r<strong>and</strong>om(width), r<strong>and</strong>om(height), 5+r<strong>and</strong>om(15), 5+r<strong>and</strong>om(15));<br />

}<br />

// build pixel array of the screen<br />

loadPixels();<br />

// set mask<br />

img.mask(pixels);<br />

//draw image<br />

image(img, 0, 0, 600, 400);<br />

Figure 10-35. Pixel Array Mask sketch<br />

Since you can collect the pixels in the display window using loadPixels(), you can generate<br />

a mask with any of <strong>Processing</strong>’s drawing functions, which is exactly what I did in this<br />

example. Using the rect() comm<strong>and</strong>, I created 600 rectangles with a fill of 255, <strong>and</strong> then<br />

I called loadPixels(), which created a pixel array of the image. If you specify an RGB fill<br />

value, the mask utilizes the value of the blue color component of the pixels. You can also<br />

specify a grayscale value with a single argument when calling the fill or background function.<br />

0 (black) will be opaque, while 255 (white) will be totally transparent. Values between<br />

0 <strong>and</strong> 255 will have varying translucency. In the example, I set the blue component in the<br />

background color to 50, giving the pixel mask some overall slight translucency, allowing<br />

the image to show through the background color a little. I gave the rectangles a fill of 255,<br />

fully revealing parts of the image through the little rectangle windows. If you’re still not<br />

getting this, try changing some of the values <strong>and</strong> playing with the code—it’s the best way<br />

to really underst<strong>and</strong> what’s happening.<br />

COLOR AND IMAGING<br />

451<br />

10

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

Saved successfully!

Ooh no, something went wrong!