Posted By

forchid on 06/23/10


Tagged

hex color RGB


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

socialflasher
shalomfriss
PixelJuice


RGB, CMYK, HEX


 / Published in: ActionScript 3
 

  1. public static function RGBtoHEX( r:Number, g:Number, b:Number ):uint
  2. {
  3. return r << 16 | g << 8 | b;
  4. }
  5.  
  6. public static function CMYKtoRGB( c:Number, m:Number, y:Number, k:Number ):Object
  7. {
  8.  
  9. // this is approximate but close enough
  10. var r:Number;
  11. var g:Number;
  12. var b:Number;
  13.  
  14. r = 255 - (Math.round (2.55 * (c + k)));
  15. g = 255 - (Math.round (2.55 * (m + k)));
  16. b = 255 - (Math.round (2.55 * (y + k)));
  17.  
  18. if (r < 0) r = 0;
  19. if (g < 0) g = 0;
  20. if (b < 0) b = 0;
  21.  
  22. return { R:r, G:g, B:b };
  23. }
  24.  
  25. public static function CMYKtoHEX( c:Number, m:Number, y:Number, k:Number ):uint
  26. {
  27. var obj:Object = CMYKtoRGB(c, m, y, k);
  28.  
  29. return RGBtoHEX( obj.R, obj.G, obj.B );
  30. }
  31.  
  32. HEX-->RGB : R/255, G/255, B/255

Report this snippet  

You need to login to post a comment.