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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

450<br />

Figure 10-34. Mask the Sky with Gradient sketch<br />

When using a pixel array mask instead of an image, the pixel array size should be the same<br />

length (number of pixels) as the image you’re masking, which means that if your image is<br />

600 ✕ 400, your pixel array should have a length of 240,000 (image width ✕ image height).<br />

Pixel array masks are a very cool feature in <strong>Processing</strong> that are a little hard to underst<strong>and</strong><br />

at first. Besides providing the ability to create interesting collaged effects, they can also be<br />

used to generate a dynamic mask at runtime. In the next example, shown in Figure 10-35,<br />

I’ll create a pixel array mask composed of 2,000 r<strong>and</strong>om rectangles. The image you use<br />

needs to be the same dimensions as the display window.<br />

// Pixel Array Mask<br />

size(600, 400);<br />

// set background--the blue channel<br />

// contributes to pixel mask<br />

background(180, 90, 50);<br />

//load but don't display image<br />

PImage img = loadImage("changsha.jpg");<br />

// create a mask composed of rectangles<br />

fill(255);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!