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.

values, just to illustrate the possibility. This second nested for loop is pretty frightening<br />

looking, so don’t give yourself a hard time if you don’t feel like unraveling it. You can also<br />

specify individual component color ranges for RGB mode, again specifying one or three<br />

optional arguments when calling the colorMode(RGB) function; I’ll leave that for you to try<br />

on your own.<br />

More convenient color functions<br />

Before moving on to imaging, I want to look at some more convenient color functions<br />

included in <strong>Processing</strong>. For creating quick, easy color blends, <strong>Processing</strong> includes two<br />

functions: blendColor() <strong>and</strong> lerpColor(). Here’s a blendColor() example, shown in<br />

Figure 10-14:<br />

//blendColor<br />

size(400, 400);<br />

smooth();<br />

noStroke();<br />

color c1 = color(255, 127, 0);<br />

color c2 = color(0, 75, 150);<br />

color[] blends = {<br />

blendColor(c1, c2, ADD), /*tan*/<br />

blendColor(c1, c2, SUBTRACT), /*red*/<br />

blendColor(c1, c2, DARKEST), /*green*/<br />

blendColor(c1, c2, LIGHTEST) /*pink*/<br />

};<br />

// background<br />

fill(c1);<br />

rect(0, 0, width, height);<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!