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

forked from: forked from: Explosions (now clickable)

// forked from uwi's forked from: Explosions (now clickable)
// forked from makc3d's Explosions (now clickable)
// forked from makc3d's Explosions
package {
    import flash.filters.*;
    import flash.geom.*;
    import flash.display.*;
    import flash.events.*;

    [SWF(backgroundColor="#000000")]
    public class FlashTest extends Sprite {
        private var bmd : BitmapData;
        private var cell : Shape;

        private var r : Function = Math.random;
        private var mat : Matrix = new Matrix();
        private const R : uint = 90;
        private var _blurs : Array;
 
        private var _p : uint = 0;
 
        // yeah, those fake-looking explosions...
        private function boo (ss : Array):Array {
            var ret : Array = [];
            
            bmd.lock();
            for each(var s : Seed in ss){
                if(s.v < 10)continue;
                
               if(Math.random() < 0.4){
                    s.x += (r() - r()) * s.v,
                    s.y += (r() - r()) * s.v,
                    ret.push(s);
                    continue;
                }
                 
                mat.identity();
                mat.scale(s.v, s.v);
                mat.rotate(Math.PI * 2 * r());
                mat.translate(s.x, s.y);
//                cell.filters = [_blurs[uint(s.v/2)]];
                cell.filters = [_blurs[uint(7 + s.v/8)]];
                // new BlurFilter (s.v / 3, s.v / 3) ];
                
                bmd.draw(cell, mat, null, BlendMode.ADD);
            
                ret.push(new Seed(
                    s.x + (r() - r()) * s.v,
                    s.y + (r() - r()) * s.v,
                    s.v * (0.8 + 0.2 * r())
                    ));
                if(_p % 3 < 2 && s.v > 30){
                    ret.push(new Seed(
                        s.x + (r() - r()) * s.v,
                        s.y + (r() - r()) * s.v,
                        s.v * (0.8 + 0.2 * r())
                    ));
                }
                _p++;
            }
            bmd.unlock();
            
            return ret;
        }

        private function init() : void
        {
            bmd = new BitmapData(465, 465, false, 0x000000);
            addChild(new Bitmap(bmd));

            cell = new Shape();
            repaint(0x3f170d);
            
            _blurs = new Array(uint(R / 2) + 1);
            for(var i : uint = 0;i <= R / 2;i++){
                _blurs[i] = new BlurFilter(i, i);
            }
        }
        
        private function repaint(c : uint) : void
        {
            var g : Graphics = cell.graphics;
            g.beginFill (c);
            g.drawRect (-0.5, -0.5, 1.0, 1.0); 
            g.endFill ();
        }

        public function FlashTest() {
            init();
            
            // catch clicks
            buttonMode = useHandCursor = true;
            stage.addEventListener (MouseEvent.CLICK, onClick);
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private var _t : uint;
        private var _seeds : Array;
        
        private function onEnterFrame(e : Event) : void
        {
            if(_seeds.length > 0){
                _seeds = boo(_seeds);
            }
            bmd.colorTransform(bmd.rect, new ColorTransform(0.992, 0.99, 0.99));
//            bmd.applyFilter(bmd, bmd.rect, new Point(), new BlurFilter(6, 6));
            
            _t++;
        }

        private function onClick (e:MouseEvent):void {
            bmd.fillRect(bmd.rect, 0x000000);
            _t = 0;
            
            var s : Seed = new Seed(stage.mouseX, stage.mouseY, R);
            _seeds = boo([s]);
        }
    }
}

class Seed
{
    public var x : Number;
    public var y : Number;
    public var v : Number;
    
    public function Seed(x : Number, y : Number, v : Number)
    {
        this.x = x;
        this.y = y;
        this.v = v;
    }
}