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

422<br />

I used a changing interpolation value in the last example to create a gradient blend<br />

between the two color arguments through the display window. Try changing the starting<br />

color values as well as the variables stepsH <strong>and</strong> stepsW (which can be different from one<br />

another) to alter the color gradient.<br />

In addition to blendColor() <strong>and</strong> lerpColor(), <strong>Processing</strong> includes seven other h<strong>and</strong>y<br />

functions for accessing individual color component values. I’ve included six of these functions<br />

within the next example, which outputs the individual color components (R, G, <strong>and</strong><br />

B) as well as hue, saturation, <strong>and</strong> brightness values; I didn’t include alpha(), but it works<br />

similarly to the other six (the sketch output can be seen in Figure 10-16):<br />

// Color Component Functions<br />

color c1 = color(123, 200, 52);<br />

println("Default RGB, 255");<br />

println("red = "+ red(c1));<br />

println("green = "+ green(c1));<br />

println("blue = "+ blue(c1));<br />

println("hue = "+ hue(c1));<br />

println("saturation = "+ saturation(c1));<br />

println("brightness = "+ brightness(c1));<br />

println("\nSt<strong>and</strong>ard HSB 360, 100, 100");<br />

colorMode(HSB, 360, 100, 100);<br />

println("red = "+ red(c1));<br />

println("green = "+ green(c1));<br />

println("blue = "+ blue(c1));<br />

println("hue = "+ hue(c1));<br />

println("saturation = "+ saturation(c1));<br />

println("brightness = "+ brightness(c1));<br />

println("\nAlternative RGB 1.0");<br />

colorMode(RGB, 1.0);<br />

println("red = "+ red(c1));<br />

println("green = "+ green(c1));<br />

println("blue = "+ blue(c1));<br />

println("hue = "+ hue(c1));<br />

println("saturation = "+ saturation(c1));<br />

println("brightness = "+ brightness(c1));

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

Saved successfully!

Ooh no, something went wrong!