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

420<br />

Figure 10-14. blendColor() sketch<br />

blendColor() takes two colors as arguments <strong>and</strong> a third mode argument that controls<br />

how the two colors are blended. The different modes are BLEND, ADD, SUBTRACT, DARKEST,<br />

<strong>and</strong> LIGHTEST. The underlying math behind each of these modes is a little complicated—<br />

I’ll look at that a bit later in the chapter when I discuss imaging, which includes a similar<br />

blending function. (Please note that as of this writing, BLEND mode, which I did not include<br />

in the example, requires the second color argument in the blendColor() call to have an<br />

alpha setting below 255, or no apparent blend will be detectable.)<br />

An alternative to blendColor() is lerpColor(). The lerp part of the function name refers<br />

to linear interpolation. Interpolation just means finding values between other discrete<br />

values. <strong>Processing</strong> actually includes a math function called lerp() that does just this.<br />

Here’s a lerp() example:<br />

// lerp()<br />

int a = 1;<br />

int b = 2;<br />

int steps = 5;<br />

float interpolationValue = 1.0/steps;<br />

for (int i=1; i

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

Saved successfully!

Ooh no, something went wrong!