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

FakeParticle

Get Adobe Flash player
by soundkitchen 25 Feb 2009
    Embed
package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;
    import flash.geom.Matrix;
    import flash.geom.Point;

    [SWF(width=500, height=500, frameRate=30, backgroundColor=0x000000)]
    public class FakeParticle extends Sprite
    {
        public static const BUG_LENGTH:int = 5;

        private var bmd:BitmapData;
        private var canvas:Sprite;
        private var bugs:Vector.<Shape>;
        private var fBlur:BlurFilter;

        /**
         *  Constructor.
         */
        function FakeParticle()
        {
            addEventListener(Event.ADDED_TO_STAGE, initialize);
        }

        /**
         *  initialize the object.
         */
        private function initialize(evt:Event):void
        {
            removeEventListener(evt.type, arguments.callee);

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            fBlur = new BlurFilter(6.0, 6.0, BitmapFilterQuality.LOW);

            bmd = new BitmapData(500, 500, true, 0);
            addChild(new Bitmap(bmd));

            canvas = new Sprite();
            bugs = new Vector.<Shape>(BUG_LENGTH, true);

            var i:int, s:Shape, g:Graphics;
            for (i=0; i<BUG_LENGTH; i++)
            {
                s = new Shape();
                g = s.graphics;
                g.beginFill(genColor());
                g.drawCircle(0, 0, 7);
                g.endFill();
                canvas.addChild(s);
                bugs[i] = s;
            }

            addEventListener(Event.ENTER_FRAME, step);
        }

        private function step(evt:Event):void
        {
            var r:Number, d:Number, s:Shape;
            for each (s in bugs)
            {
                r = Math.random() * Math.PI * 2;
                d = Math.random() * 80;
                s.x = mouseX + Math.sin(r) * d;
                s.y = mouseY + Math.cos(r) * d;
            }

            var mtx:Matrix = new Matrix();
            mtx.scale(canvas.scaleX, canvas.scaleY);

            bmd.lock();
            bmd.draw(canvas, mtx, null, BlendMode.ADD);
            bmd.applyFilter(bmd, bmd.rect, new Point(), fBlur);
            bmd.unlock();
        }
    }
}

function genColor():uint
{
    var f:Function = function():int
    {
        return Math.round(Math.random() * 255);
    }
    return f() << 16|f() << 8|f();
}