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.

separate out <strong>and</strong> invert component color values<br />

float r = abs(red(pixels[i])-invertFactor);<br />

float g = abs(green(pixels[i])-invertFactor);<br />

float b = abs(blue(pixels[i])-invertFactor);<br />

// put pixel back together<br />

pixels[i] = color(r, g, b);<br />

// each row interval decrements invertFactor<br />

if (i>0 && i% width==0){<br />

invertFactor-=(255.0/height);<br />

}<br />

}<br />

updatePixels();<br />

Figure 10-37. From Neg to Pos sketch<br />

Besides showcasing a custom invert filter, this last sketch demonstrated another example<br />

of the usefulness of the modulus operator:<br />

if (i>0 && i% width==0){<br />

By dividing i by the display window width <strong>and</strong> checking for a 0 remainder, I ensured that<br />

the variable invertFactor would only be decremented per each row of pixels, giving me<br />

a smooth gradation down the image.<br />

COLOR AND IMAGING<br />

455<br />

10

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

Saved successfully!

Ooh no, something went wrong!