Gradiation(2)

by bradsedito forked from forked from: gradation (diff: 82)
♥0 | Line 61 | Modified 2011-11-09 06:27:20 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tb8p
 */





package 
{
    import flash.events.Event;
    import flash.display.Graphics;
    import flash.display.Sprite;
    
    public class Gradiation extends Sprite 
    {
        public  var color:uint;
        public  var index:uint;
        public  var ratio:Number = new Number( index/465 );
        public  var ratioR:Number = new Number( 1.0 - ratio );
        public  var topColorR:uint;
        public  var topColorG:uint;
        public  var topColorB:uint;
        public  var bottomColorR:uint;
        public  var bottomColorG:uint;
        public  var bottomColorB:uint;
        public  var cr:uint;
        public  var cg:uint;
        public  var cb:uint;
        private var bg_TOP:Sprite = new Sprite;
        private var bg_BTM:Sprite = new Sprite;
        
        
        public function Gradiation() 
        {
            
            drawBG(
                   this.graphics,  // graphics
                   000, 150, 200,  // topColor
                   000, 000, 100   // bottomColor
            ); 
            
            bg_TOP.scaleY = .5;
            bg_TOP.y = 0;
            
            bg_BTM.scaleY = .5;
            bg_BTM.y = stage.stageHeight/2;

        }
        
        
        public function loop( event:Event ):void
            {
                    cr     =  (topColorR * ratioR) + (bottomColorR * ratio);
                    cg     =  (topColorG * ratioR) + (bottomColorG * ratio);
                    cb     =  (topColorB * ratioR) + (bottomColorB * ratio);
                    color  =  (cr << 16) + (cg << 8) + (cb << 0);
                    
                    bg_TOP.graphics.beginFill(color);
                    bg_TOP.graphics.drawRect(0, 1 * index, 465, 1); 
                    bg_TOP.graphics.endFill();
                    
                    bg_BTM.graphics.beginFill(color);
                    bg_BTM.graphics.drawRect(0, 1 * index, 465, 1);
                    bg_BTM.graphics.endFill();
            }

        
        
        public function drawBG
        (
                g:Graphics, 
                topColorR:uint, topColorG:uint, topColorB:uint, 
                bottomColorR:uint, bottomColorG:uint, bottomColorB:uint
        ):void 
        {   //g.clear();            
            for (var index:uint = 0; index < 465; ++index) 
            {
                this.addEventListener(Event.ENTER_FRAME, loop);
            }
            
                //var ratio:Number = Number(index) / 465;
                //var ratioR:Number = 1.0 - ratio;
                //var cg:uint = (topColorG * ratioR) + (bottomColorG * ratio);
                //var cb:uint = (topColorB * ratioR) + (bottomColorB * ratio);
                //var color:uint = (cr << 16) + (cg << 8) + (cb << 0);                
                //g.beginFill(color);
                //g.drawRect(0, 1 * index, 465, 1);
                //g.endFill();
            
        }
        
        
    }
}