Hi Jeff, 

Here's a class that will generate an array for N elements that blends
between two RGB values.

Example:
        import org.bespoke.color.ColorBlend;
        var myBlender:ColorBlend=new ColorBlend(0xFF0000,0x00FF00);

        //to get the RGBN value at 46% between the two...
        var resultColor:Number= myBlender.getRGBAt(.46);

        //get the blend in an array of 20 steps....
        var myRGBArray:Array=myBlender.getArrayOfLength(20);

Hope this helps,
Cheers,
t


//----------------------------------------------------
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;

class org.bespoke.color.ColorBlend extends Object{
        
        public var start_rgb:Number=0x000000;
        public var end_rgb:Number=0xFFFFFF;
        
        private var colorTransform:ColorTransform;
        private var matrix:Matrix;
        
        public var bmp:BitmapData;
        public var bmp_end:BitmapData;
        
        function ColorBlend(c1:Number,c2:Number){
                if(c1!=undefined){start_rgb=c1;}
                if(c2!=undefined){end_rgb=c2;}          
                bmp=new BitmapData(1,1,true);
                bmp_end=new BitmapData(1,1,true);
                matrix=new Matrix();
                colorTransform=new ColorTransform();
        }
        
        function getRGBAt(n:Number):Number{
                //n should be a normalised float (0-1.0)
                // although the range -1.0 <=> 1.0 is valid

                bmp.setPixel(0,0,start_rgb);
                bmp_end.setPixel(0,0,end_rgb);
                colorTransform.alphaMultiplier=n;
                bmp.draw(bmp_end,matrix,colorTransform);
                return bmp.getPixel(0,0);
        }
        
        function getArrayOfLength(n:Number):Array
        {
                var result:Array=new Array();
                 for(var i:Number=0;i<n;i++){
                         result.push(getRGBAt(i/n));
                        }
                        return result;
        }
}
//----------------------------------------------------
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to