Skip to content

Instantly share code, notes, and snippets.

@jeremyfromearth
Created November 1, 2010 16:23
Show Gist options
  • Save jeremyfromearth/658449 to your computer and use it in GitHub Desktop.
Save jeremyfromearth/658449 to your computer and use it in GitHub Desktop.
A plug-in for tweening hex values, useful for creating color gradient tweens
package aze.motion.specials
{
import aze.motion.*;
import aze.motion.specials.*;
/**
* A hex tween plug-in for use with Eaze animation engine
* For instructions on use visit:
* http://labs.makemachine.net/2010/10/gradient-tween-for-eaze/
*
* @author jeremynealbrown
*/
public class PropertyHex extends EazeSpecial
{
protected var targets:Vector.<Object>;
protected var properties:Vector.<String>;
protected var colors:Vector.<Vector.<Number>>;
static public function register():void
{
EazeTween.specialProperties[ 'hex' ] = PropertyHex;
}
public function PropertyHex(target:Object, property:*, value:*, next:EazeSpecial)
{
super(target, property, value, next);
targets = new Vector.<Object>();
properties = new Vector.<String>();
colors = new Vector.<Vector.<Number>>();
for (var prop:String in value)
{
var start:uint = uint(target[prop]);
var end:uint = uint(value[prop])
var r:Number = start >> 16;
var g:Number = (start >> 8) & 0xff;
var b:Number = start & 0xff;
var n:int = colors.length;
targets[ n ] = target;
properties[n] = prop;
colors[n] = Vector.<Number>([ r, (end >> 16) - r,
g, ((end >> 8) & 0xff) - g,
b, (end & 0xff) - b] );
}
}
override public function update(ke:Number, isComplete:Boolean):void
{
var i:int;
var a:Vector.<Number>;
var l:int = colors.length;
for (i = 0; i < l; i++)
{
a = colors[i];
targets[ i ][ properties[ i ] ] = ( ( a[ 0 ] + ( ke * a[ 1 ] ) ) << 16 | // -- r
( a[ 2 ] + ( ke * a[ 3 ]) ) << 8 | // -- g
( a[ 4 ] + ( ke * a[ 5 ]) ) ); // -- b
}
}
override public function dispose():void
{
target = null;
targets.slice( 0 );
properties.slice( 0 );
if (next) next.dispose();
next = null;
colors.slice( 0 );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment