Tweening colors?

By Thomas H

This pretty useful function returns the correct color value between to colors. h1 and h2 params being the colors and p being the position in between in percent.

private function interpolateColor(h1:Number, h2:Number, p:Number) : Number { 
	return ((h1>>16)+((h2>>16)-(h1>>16))*p)<<16
                  |(h1>>8&0xFF)+((h2>>8&0xFF)-(h1>>8&0xFF))*p<<8
                  |(h1&0xFF)+((h2&0xFF)-(h1&0xFF))*p; 
}
  1. Alexander says:

    If you find all those ‘>>’, ‘&’, and ‘|’ characters confusing, I highly recommend this article on Bitwise operations: http://www.gamedev.net/reference/articles/article1563.asp

  1. There are no trackbacks for this post yet.

Leave a Reply