In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

[ff]: simple bitmap Effect

Get Adobe Flash player
by bradsedito 29 Jan 2013
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cQFL
 */






package  
{
    import flash.geom.ColorTransform;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.display.Shape;
    import flash.filters.ConvolutionFilter;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.display.Sprite;


    public class testwater extends Sprite 
    {                
        private var h : int;
        private var w : int;
        private var mainbmp : Bitmap;
        private var chromeFilter : ConvolutionFilter;
        private var shape : Shape;
        private var bmpBuffer : BitmapData;
        private var blackfilter : ConvolutionFilter;
        private var isBlack : Boolean = true;
        private var blurFilter : BlurFilter;
        private var p : Point;
        private var colors : ColorTransform;


        public function testwater() 
        {
            if(stage) inits()
            else addEventListener(Event.ADDED_TO_STAGE, inits)
        }


        private function inits(event : Event=null ): void 
        {            
            w=stage.stageWidth,
            h=stage.stageHeight,
            mainbmp=new Bitmap(null);
            mainbmp.bitmapData=new BitmapData(w, h,false,0x000000)
            addChild(mainbmp)
            shape=new Shape()

            with( shape.graphics )
            {
                beginFill( 0xffffff )
                drawCircle( 0,0,20 )
                endFill()
            }

            shape.filters  =  [  new BlurFilter( 20,20,3 )  ]
            var matrix:Matrix=new Matrix()
            matrix.translate(mainbmp.bitmapData.width/2, mainbmp.bitmapData.height/2)
            bmpBuffer=new BitmapData(w, h,false,0x000000)
            
            bmpBuffer.draw(shape,matrix)

            var chromeMatrix:Array = 
            [
                0.05, 1.0,
                0.05, 1.0,
                0.00, 1.0, 
                0.05, 0.1,
                0.05
            ] 

            chromeFilter  =  new ConvolutionFilter( 3,3,chromeMatrix,3 );

            var blackMatrix:Array=
            [
                1.0,  1.0,  1.0,
                1.0, -0.1,  1.0,
                1.0,  1.0,  1.0
            ]        

            blackfilter  =  new ConvolutionFilter(3,3,blackMatrix,9)
            blurFilter   =  new BlurFilter( 30,30,3 )
            p            =  new Point()
            colors       =  new ColorTransform()
            
            addEventListener(Event.ENTER_FRAME, loop)
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemovie)
        }



        private function mousemovie(event : MouseEvent) : void {

            colors.redMultiplier=Math.random()
            colors.greenMultiplier=Math.random()
            colors.blueMultiplier=Math.random()

            if(isBlack) 
            {
                bmpBuffer.draw(  shape, new Matrix(1,0,0,1,mouseX,mouseY), colors  )               
            }            
        }


        private function loop( event:Event ):void 
        {            
            if(mainbmp.bitmapData.getPixel(0, 0)==0xffffff && mainbmp.bitmapData.getPixel(w-1,h-1)==0xffffff && mainbmp.bitmapData.getPixel(w-1,0)==0xffffff && mainbmp.bitmapData.getPixel(0,h-1)==0xffffff)
            {
                isBlack=false
                removeEventListener(Event.ENTER_FRAME, loop)
                addEventListener(Event.ENTER_FRAME, checkBlackPoint)
                function checkBlackPoint():void{
                mainbmp.bitmapData.applyFilter(bmpBuffer, mainbmp.bitmapData.rect, p,blackfilter)
                if(mainbmp.bitmapData.getPixel(0, 0)==0x000000) {
                removeEventListener(Event.ENTER_FRAME, checkBlackPoint)
                addEventListener(Event.ENTER_FRAME, loop)
                isBlack=true
                }
                }
            }

            else 
            {        
                mainbmp.bitmapData.applyFilter(bmpBuffer, mainbmp.bitmapData.rect, p,blurFilter)
                mainbmp.bitmapData.applyFilter(bmpBuffer, mainbmp.bitmapData.rect, p,chromeFilter)
                }

                bmpBuffer=mainbmp.bitmapData
        }
    
    }    
}