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.

I want to mention two final points about using these functions. First, according to the<br />

<strong>Processing</strong> API reference, these functions are somewhat slow—say, for extracting component<br />

data from many colors at a time. The reference suggests using bitwise operations if<br />

speed is an issue. I cover bitwise operations in detail in Appendix B, <strong>and</strong> I also look at some<br />

examples that utilize them a little later in this chapter. Second, these seven functions<br />

return a float value, regardless of whether you originally specified int values when you<br />

created the color. So, for example, if you created a color using the default RGB mode (e.g.,<br />

color c = color(200, 150, 74)) <strong>and</strong> you then called red(c), the value returned would<br />

be 200.0, not 200. I know it’s just a 0 after the dot, but this could cause problems if you<br />

tried to assign the returned value to a variable declared as type int. Try running the following<br />

three lines; you should get a compiler error:<br />

Imaging<br />

//generates a compiler error<br />

color c = color(200, 134, 119);<br />

int r = red(c);<br />

Figure 10-16. Color Component Functions sketch<br />

Thus far in the book, I’ve been utilizing a vector graphics approach, in which images are<br />

created <strong>and</strong> manipulated using mathematical expressions that plot a shape <strong>and</strong> apply rendering<br />

attributes, such as stroke weight, fill color, corner joins, <strong>and</strong> so on. <strong>Processing</strong> has<br />

the ability to work deeper, down at the pixel or raster level. In a sense, you’ve been getting<br />

near the pixel level when you used 1 ✕ 1 pixel rectangles to create some gradients.<br />

However, using rectangles to represent pixels is a very inefficient way to approach imaging.<br />

In addition, most people connect photo manipulation with imaging, which you’d be hardpressed<br />

to do with a series of rect() calls.<br />

COLOR AND IMAGING<br />

423<br />

10

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

Saved successfully!

Ooh no, something went wrong!