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.

The mask works like an alpha channel. A value of 0 (black) will conceal the image pixel,<br />

while a value of 255 (white) will fully reveal the image pixel. Values between 0 <strong>and</strong> 255 will<br />

display the masked pixels in the image with varying degrees of translucency. In the next<br />

sketch, I used one image to mask out the sky area of another image, allowing the display<br />

window background color to show through (where the 0 values of the mask pixels are). I<br />

made the sky-shaped mask image from the original image, which I was able to select <strong>and</strong><br />

convert using Photoshop. In the two example images, the first image uses a 100 percent<br />

black sky mask, while the second uses a linear gradient from black (top of the sky) to white<br />

(bottom of the sky). The two images I used were both 600 ✕ 480 pixels (see Figures 10-33<br />

<strong>and</strong> 10-34):<br />

// Mask the Sky<br />

size(600, 480);<br />

background(185, 185, 250);<br />

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

PImage mask = loadImage("harbor2_mask.jpg");<br />

img.mask(mask);<br />

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

Figure 10-33. Mask the Sky sketch<br />

COLOR AND IMAGING<br />

449<br />

10

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

Saved successfully!

Ooh no, something went wrong!