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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

770<br />

11111111111111111111111111001000<br />

& 00000000000000000000000011111111<br />

00000000000000000000000011001000<br />

Removing the extra zeros on the left of the number, we’re left with 11001000, which in<br />

decimal notation is equal to 200—the value of the red component.<br />

You can (of course) also use bitwise operations to extract the green, blue, <strong>and</strong> alpha values<br />

from the color, using the following expressions:<br />

int g = myColor >> 8 & 0xFF;<br />

int b = myColor & 0xFF;<br />

int a = myColor >> 24 & 0xFF;<br />

Finally, to put the individual color component values back together into a packed 32-bit<br />

integer, you’d use the left shift operator <strong>and</strong> the bitwise OR operator, which can be done<br />

in multiple lines of code, like this:<br />

color newColor = a 8 & 0xFF;<br />

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

int b = myColor & 0xFF;<br />

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

// build newColor from myColor components<br />

color newColor = (a

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

Saved successfully!

Ooh no, something went wrong!