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.

This last sketch couldn’t be simpler. The INVERT argument inverts the pixel color component<br />

values. However, that’s all you can do with it. Now, let’s implement our own custom<br />

invert filter. Inverting the color component value is as simple as subtracting 255 from each<br />

component. However, doing that will also generate a negative value or 0. I want positive<br />

color component values in the range of 0 to 255, so I need to remove the negative sign.<br />

Two simple ways to do that would be to multiply each value by –1, or use <strong>Processing</strong>’s<br />

abs() function, which returns the absolute value of the argument.<br />

//custom invert--version 1<br />

// image should be 600 x 400 pixels<br />

size(600, 400);<br />

background(255);<br />

PImage img = loadImage("view.jpg");<br />

image(img, 0, 0);<br />

loadPixels();<br />

for (int i=0; i> 16 & 0xFF)-255);<br />

int g = abs((pixels[i] >> 8 & 0xFF)-255);<br />

int b = abs((pixels[i] & 0xFF)-255);<br />

int a = pixels[i] >> 24 & 0xFF;<br />

pixels[i] = (a

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

Saved successfully!

Ooh no, something went wrong!