Posted By

dx0ne on 02/23/09


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

zimmen
toxin20
thastylos
tspitzr


AS3: Interpolate color


 / Published in: ActionScript 3
 

URL: http://www.actionscript.org/forums/showpost.php3?p=794474&postcount=4

  1. //
  2. //found at http://www.actionscript.org/forums/showpost.php3?p=794474&postcount=4
  3. //
  4. public static function interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint
  5. {
  6. var q:Number = 1-progress;
  7. var fromA:uint = (fromColor >> 24) & 0xFF;
  8. var fromR:uint = (fromColor >> 16) & 0xFF;
  9. var fromG:uint = (fromColor >> 8) & 0xFF;
  10. var fromB:uint = fromColor & 0xFF;
  11. var toA:uint = (toColor >> 24) & 0xFF;
  12. var toR:uint = (toColor >> 16) & 0xFF;
  13. var toG:uint = (toColor >> 8) & 0xFF;
  14. var toB:uint = toColor & 0xFF;
  15. var resultA:uint = fromA*q + toA*progress;
  16. var resultR:uint = fromR*q + toR*progress;
  17. var resultG:uint = fromG*q + toG*progress;
  18. var resultB:uint = fromB*q + toB*progress;
  19. var resultColor:uint = resultA << 24 | resultR << 16 | resultG << 8 | resultB;
  20. return resultColor;
  21. }

Report this snippet  

You need to login to post a comment.