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 10-45. blend() Function with Altered Destination<br />

Image Coordinates sketch<br />

In the blend() Function with Altered Source Image Coordinates example, I set the y coordinate<br />

of the source image to 300 <strong>and</strong> the height of the source image to 10. You can think<br />

of this as copying a segment (specified by these source coordinates) of the image <strong>and</strong> then<br />

stretching this segment to fit the destination coordinates, which I set to the full size of the<br />

display window.<br />

In the second example, I made the source coordinates the size of the display window, but<br />

made the destination coordinates only include the bottom half of the display window.<br />

Besides the source <strong>and</strong> destination coordinates, the blend() method also requires a mode<br />

argument. I specified DARKEST in the last examples, but there are a few others as well.<br />

The blend() modes include BLEND, ADD, LIGHTEST, SUBTRACT, <strong>and</strong> DARKEST. The math<br />

behind these modes involves, as you might suspect, bitwise operations. The <strong>Processing</strong> reference<br />

lists the blending expressions as follows:<br />

BLEND: Linear interpolation of colors: C = A * factor + B<br />

SUBTRACT: Subtractive blending with black clip: C = max(B – A * factor, 0)<br />

ADD: Additive blending with white clip: C = min(A * factor + B, 255)<br />

DARKEST: Only the darkest color succeeds: C = min(A * factor, B)<br />

LIGHTEST: Only the lightest color succeeds: C = max(A * factor, B)<br />

COLOR AND IMAGING<br />

463<br />

10

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

Saved successfully!

Ooh no, something went wrong!