views:

475

answers:

4

In Actionscript 3.0, the Color class has a method called interpolateColor. It seems strange to me, but the method takes two unsigned integers for the colors as opposed to two instances of Color. Additionally, it returns an unsigned integer for the resultant color. Anyhow, I don't see anything in the API for converting a Color to an unsigned integer or for simply interpolating between two instances of Color. Is it possible to interpolate between two instances of Color without writing the code to convert them to unsigned integers myself?

A: 

That is somewhat inconvenient, but it looks like converting it to a number is the only way. Here is a post about it, with this code:

public static function interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint
{
    var q:Number = 1-progress;
    var fromA:uint = (fromColor >> 24) & 0xFF;
    var fromR:uint = (fromColor >> 16) & 0xFF;
    var fromG:uint = (fromColor >>  8) & 0xFF;
    var fromB:uint =  fromColor        & 0xFF;

    var toA:uint = (toColor >> 24) & 0xFF;
    var toR:uint = (toColor >> 16) & 0xFF;
    var toG:uint = (toColor >>  8) & 0xFF;
    var toB:uint =  toColor        & 0xFF;

    var resultA:uint = fromA*q + toA*progress;
    var resultR:uint = fromR*q + toR*progress;
    var resultG:uint = fromG*q + toG*progress;
    var resultB:uint = fromB*q + toB*progress;
    var resultColor:uint = resultA << 24 | resultR << 16 | resultG << 8 | resultB;
    return resultColor;  
}
jtbandes
+1  A: 

All colors in the flash player are treated as an unsigned ints. The Color class is specific to the Flash IDE and extends ColorTransform. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/motion/Color.html#propertySummary

So in your case, all you need to do is use the ".color" property of your Color classes. eg., to get the actual color, or just use the "interpolateTransform" function instead which does go from ColorTransform to ColorTranform.

Glenn
A: 

Can you not use ColorTransform instances ? You get the colorTransfrom from instanceMovieClip.transform.colorTransorm then interpolate the colorTransofrm with Color.interpolateTransform ?

I don't think I understand what you're trying to achieve (why do you need to interpolate two Color Instances ? and not colors(ints) or colorTransforms) ?

George Profenza
A: 

Hi, maybe it is a bit late, I just arrived here in this page by chance but, I was facing a similar problem with the interpolation colour when resizing images and at the end the best solution I found was using Bicubic for 2D transformations and Hermite for 1D. take a look on it http://www.yoambulante.com/en/labs/interpolation.php cheers!

Alex Nino