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

color blur

move mouse. :)
Get Adobe Flash player
by Caiim. 15 Sep 2012
    Embed
/**
 * Copyright Caiim. ( http://wonderfl.net/user/Caiim. )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7m6L
 */

package {
    import flash.filters.ColorMatrixFilter;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Graphics;
    import flash.display.Sprite;

    public class FlashTest extends Sprite {
        private var diamondVectorCont:Vector.<Diamond> = new Vector.<Diamond>();
        private var diamondContainer:Sprite = new Sprite();
        private var diamondBitmap:Bitmap = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0))
        
        public function FlashTest() 
        {
            addChild(diamondBitmap);
            addChild(diamondContainer);
            addListener();
        }
        
        private function addListener():void
        {
            stage.addEventListener(MouseEvent.MOUSE_MOVE, addDiamonds);
            stage.addEventListener(Event.ENTER_FRAME, moveDiamondsToBitmap);
        }
        
        private function moveDiamondsToBitmap(e:Event):void
        {
            for(var i:int = diamondVectorCont.length-1 ; i >= 0 ; i--)
            {
                var d:Diamond = diamondVectorCont[i];
                if(!d.alive)
                {
                    diamondContainer.removeChild(d);
                    diamondVectorCont.splice(i, 1);
                    var s:Sprite = new Sprite();
                    s.addChild(d);
                    diamondBitmap.bitmapData.draw(s);
                }
            }            
            diamondBitmap.bitmapData.applyFilter(diamondBitmap.bitmapData, diamondBitmap.bitmapData.rect, new Point(0, 0), new BlurFilter(2, 2));
        }

        private function addDiamonds(e:MouseEvent):void
        {
            for(var i:int = 0 ; i< 3;i++)
            {
                var diamond:Diamond = new Diamond(e.stageX, e.stageY);
                diamond.setDirection(Math.random()*Math.PI*2);
                diamond.setPower(5 + Math.random() * 10);
                diamondVectorCont.push(diamond);
                diamondContainer.addChild(diamond);
            }
        }        
    }
}
import flash.events.Event;


import flash.display.Sprite;
import flash.display.Graphics;
class Diamond extends Sprite
{
    private var size:int = 0,
                direction:Number = 0,
                power:Number = 0;
                
    public var alive:Boolean = false;
    
    public function Diamond(x:int,y:int)
    {

        size = 5 + Math.random() * 10;

        var g:Graphics = this.graphics;
        g.beginFill(Math.random() * 0xffffff, 0.3 + Math.random() * 0.5);
        g.moveTo(size, 0);
        g.lineTo(0, size/2);
        g.lineTo(-size, 0);
        g.lineTo(0, -size/2);

        this.x = x;
        this.y = y;
    }
    
    private function addListener():void
    {
        addEventListener(Event.ENTER_FRAME, updateMyPosition);
    }
    
    private function removeListener():void
    {
        removeEventListener(Event.ENTER_FRAME, updateMyPosition);
    }
    
    private function updateMyPosition(e:Event):void
    {
        if(alive)
        {
            this.x += Math.cos(direction) * power;
            this.y += Math.sin(direction) * power;
            this.scaleX += power/15;
            this.scaleY += power/100;
            power *= 0.9;
            if(power < 1)
            {
                power = 0;
                alive = false;
                removeListener();
            }
        }
    }
  
    public function setDirection(direction:Number):void
    {
        this.direction = direction;
        this.rotation = direction * 180 / Math.PI;
    }

    public function setPower(power:Number):void
    {
        this.power = power;
        alive = true;
        addListener();
    }
}