Created
March 31, 2010 07:04
-
-
Save fjenett/350031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extracting single channels from Processings color type | |
// | |
color c = color( 123, 234, 95, 125 ); // this is: color ( red, green, blue, alpha ) | |
println( "Color in Hex:\t0x" + Integer.toHexString( c ).toUpperCase() ); | |
int alpha = ( c >> 24 ) & 0xFF; | |
int red = ( c >> 16 ) & 0xFF; | |
int green = ( c >> 8 ) & 0xFF; | |
int blue = c & 0xFF; | |
println( "A: "+alpha+"\tR: "+red+"\tG: "+green+"\tB: "+blue ); | |
int c2 = ( alpha << 24 | red << 16 | green << 8 | blue ); | |
println( c == c2 ? "Colors are equal!" : "Nope. Somethings wrong!" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment