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.

simple-looking paint bucket tool in your favorite paint program. You don’t need to use bitwise<br />

operations, as <strong>Processing</strong> has the component property functions red(), green(),<br />

blue(), <strong>and</strong> alpha(); but there may be times when the bitwise operations will really come<br />

in h<strong>and</strong>y. Here’s a final <strong>Processing</strong> sketch that illustrates one of the things you can do with<br />

bitwise operations (shown in Figure B-7). (Please note this example requires the use of an<br />

external image, which needs to be added to the sketch’s data directory.)<br />

/*<br />

Color Variations Filter Using<br />

Bitwise Operations<br />

Ira Greenberg, November 11, 2005<br />

revised: April 3, 2007<br />

*/<br />

/*change display size to accommodate<br />

the size of your image */<br />

size(360, 600);<br />

/*remember to add an image into<br />

the sketch data directory before<br />

using loadImage() <strong>and</strong> also to update<br />

the name of the image below. */<br />

PImage img = loadImage("robin_<strong>and</strong>_sophie.jpg");<br />

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

// pixel array<br />

int[]pxls = new int[width*height];<br />

// holds shifted colors<br />

color[]newCol = new int[width*height];<br />

// keep track of pixels<br />

int pxlCounter = 0;<br />

/* loop gets color components out<br />

of color integer using bitwise operators<br />

<strong>and</strong> shifts color components before<br />

rebuilding pixel array- effect is similar<br />

to Photoshop's variations filter */<br />

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

int g = pxls[pxlCounter] >> 8 & 0xFF;<br />

int b = pxls[pxlCounter] & 0xFF;<br />

int a = pxls[pxlCounter] >> 24 & 0xFF;<br />

/* conditionals check where we are in the image<br />

min() functions keep color component values in<br />

range 0-255 to avoid psychadelic artifacting */<br />

//left column, top row(red+)<br />

if (i

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

Saved successfully!

Ooh no, something went wrong!