1 package flare.animate.interpolate
4 * Interpolator for color (<code>uint</code>) values.
6 public class ColorInterpolator extends Interpolator
8 private var _start:uint;
12 * Creates a new ColorInterpolator.
13 * @param target the object whose property is being interpolated
14 * @param property the property to interpolate
15 * @param start the starting color value to interpolate from
16 * @param end the target color value to interpolate to
18 public function ColorInterpolator(target:Object, property:String,
19 start:Object, end:Object)
21 super(target, property, start, end);
25 * Initializes this interpolator.
26 * @param start the starting value of the interpolation
27 * @param end the target value of the interpolation
29 protected override function init(start:Object, end:Object) : void
36 * Calculate and set an interpolated property value.
37 * @param f the interpolation fraction (typically between 0 and 1)
39 public override function interpolate(f:Number) : void
41 // we'll do all the work here to avoid the overhead of
42 // extra method calls (rather than call Colors.interpolate)
43 var a1:uint, a2:uint, r1:uint, r2:uint,
44 g1:uint, g2:uint, b1:uint, b2:uint;
46 // get color components
47 a1 = (_start >> 24) & 0xFF; a2 = (_end >> 24) & 0xFF;
48 r1 = (_start >> 16) & 0xFF; r2 = (_end >> 16) & 0xFF;
49 g1 = (_start >> 8) & 0xFF; g2 = (_end >> 8) & 0xFF;
50 b1 = _start & 0xff; b2 = _end & 0xFF;
52 // interpolate the color components
53 a1 += f*(a2-a1); r1 += f*(r2-r1);
54 g1 += f*(g2-g1); b1 += f*(b2-b1);
56 // recombine into final color
57 a1 = ((a1 & 0xFF) << 24) | ((r1 & 0xFF) << 16) |
58 ((g1 & 0xFF) << 8) | (b1 & 0xFF);
60 // update the property value
61 _prop.setValue(_target, a1);
64 } // end of class ColorInterpolator