Skip to content

Instantly share code, notes, and snippets.

@fjenett
Created March 31, 2010 07:04
Show Gist options
  • Save fjenett/350031 to your computer and use it in GitHub Desktop.
Save fjenett/350031 to your computer and use it in GitHub Desktop.
// 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