forked from: flash on 2010-6-23

by m0ose
♥0 | Line 83 | Modified 2010-06-24 14:04:15 | MIT License
play

ActionScript3 source code

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

package {
    import flash.filters.BlurFilter;
    import flash.display.AVM1Movie;
    import flash.filters.DisplacementMapFilter;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.Matrix;
    import flash.display.Shape;
    import flash.geom.Rectangle;
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class gradients extends Sprite
    {
        
       
        private var rec:Rectangle = new Rectangle( 0,0, stage.width, stage.height)
        private var srec:Shape = new Shape()
        
         
        gradients(null)
        
        private var matrix:Matrix = new Matrix() 
        public var  wid:int = 110
        public var strength:int = 0
        private var filt:DisplacementMapFilter 
        
        public function gradients( i:int = 1)
        {
            
            
             filt = new DisplacementMapFilter()
             filt.mapBitmap = grad()
             filt.componentX = 1
             filt.componentY = 0
             filt.scaleX = filt.scaleY = strength
  
             var bm:Bitmap = new Bitmap(quickPic() )
             bm.filters = [filt]
            
             stage.addChild( bm).name = "bms"
             stage.addEventListener( Event.ENTER_FRAME, increment)
                
        }
        
//LOOP
        private var it:int=1
        
        public function increment(e:Event = null):void
        {
             var speed:int = 40 //controls the speed
            if( it >= 314) it = 0;
            it++
            strength = Math.round(Math.sin( it / speed) * 100 )
                
            filt.scaleX = filt.scaleY = strength 
            stage.getChildByName("bms").filters=[filt]
       }
       
       //MAKE DISTORTION MAP
        public function grad():BitmapData
        {        
            matrix.createGradientBox(     wid, 
                                        stage.height, 
                                        0, 
                                        0, 
                                        0 );
        
           var gsprite:Sprite = new Sprite()
           gsprite.graphics.beginGradientFill(     "linear", 
                                                        [ 0xff0000, 0x000000 ],
                                                        [ 1, 1 ],
                                                        [ 55, 200 ],
                                                        matrix, "reflect" );
            gsprite.graphics.drawRect( 0,0,400,400)
            gsprite.filters = [ new BlurFilter(10,10,1) ]
            var res:BitmapData = new BitmapData(400,400,false, 0xf0f0f0)
            res.draw(gsprite)
            return res
        }
        
        //DRAW SILLY FACE
         public function quickPic():BitmapData
        {
            var s:Shape = new Shape()
            var result:BitmapData = new BitmapData(500,500, false, 0xffffff)
            
            s.graphics.beginFill(0x00ff00)//head
            s.graphics.lineStyle(1,0x000000)
            s.graphics.drawRect( 30,30, 30,50)
            s.graphics.drawCircle( 200,200,100)
            
           
            s.graphics.endFill()
            s.graphics.beginFill( 0xffffff,0.9)//eyes
            s.graphics.drawCircle(170,170,20)
            s.graphics.drawCircle(230,170,20)
            s.graphics.endFill()
            s.graphics.beginFill(0x000000)//pupils
            s.graphics.drawCircle(174,174,9)
            s.graphics.drawCircle(226,174,9)
            
            s.graphics.drawEllipse(170,230,70,5)
            
            result.draw( s)
            return result
        }
  
    }

}