Posted By

orazal on 08/29/07


Tagged

actionscript color


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

andrewrench


Color Utils


 / Published in: ActionScript
 

  1. function hexToRGB ( hex:Number ){
  2. var returnObj:Object = new Object();
  3. var returnObj .r = hex >> 16;
  4. var temp = hex ^ r << 16;
  5. var returnObj .g = temp >> 8;
  6. var returnObj .b = temp ^ g << 8;
  7. return returnObj;
  8. }
  9. function RGBToHex (r, g, b ){
  10. var hex = r << 16 ^ g << 8 ^ b;
  11. return hex;
  12. }
  13. /**
  14.  * Sets a object with an rbg tint
  15.  *
  16.  * @param r Red amount
  17.  * @param g Green amount
  18.  * @param b Blue amount
  19.  * @param amount The alpha amount on all colors
  20.  * @returns A color object to use with setTransform
  21.  */
  22. function setTint(r, g, b, amount):Object{
  23. var trans = new Object();
  24. trans.ra = trans.ga = trans.ba = 100 - amount;
  25. var ratio = amount / 100;
  26. trans.rb = r * ratio;
  27. trans.gb = g * ratio;
  28. trans.bb = b * ratio;
  29. return trans;
  30. }

Report this snippet  

You need to login to post a comment.