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 />

464<br />

C is the blended value, <strong>and</strong> A <strong>and</strong> B represent the two colors to blend. <strong>Processing</strong>’s min()<br />

<strong>and</strong> max() functions return the lowest <strong>and</strong> highest argument values, respectively. These<br />

functions are useful for clipping out-of-range values. For example, if one of the arguments<br />

passed to the SUBTRACT mode is less than 0, the max() function will return the 0 argument.<br />

All other in-range values will be returned. The “factor” specified in the preceding expressions<br />

is based on the alpha component of the source pixel, which is represented by the<br />

first 8 bits (from the left) of the 32-bit integer representing the pixel color. These leftmost<br />

bits are also referred to as the highest byte. Fortunately, you don’t have to worry about the<br />

internal implementation to use the blend() function.<br />

Next are examples using SUBTRACT mode (shown in Figures 10-46, 10-47, <strong>and</strong> 10-48). I’ll<br />

continue to use the same airport.jpg <strong>and</strong> towers.jpg images as in the preceding<br />

DARKEST examples.<br />

size(300, 400);<br />

background(loadImage("airport.jpg"));<br />

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

blend(img, 0, 0, 300, 400, 0, 0, 300, 400, SUBTRACT);<br />

Figure 10-46. blend() Function Using SUBTRACT Argument sketch

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

Saved successfully!

Ooh no, something went wrong!