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: forked from: flash on 2011-7-3

Get Adobe Flash player
by goldsource 15 Jul 2011
/**
 * Copyright goldsource ( http://wonderfl.net/user/goldsource )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pq2d
 */

// forked from itsukichang's forked from: forked from: flash on 2011-7-3
// forked from tomonobu's forked from: flash on 2011-7-3
package {
    import flash.display.*;
    import flash.events.*;
    import flash.filters.BlurFilter;
    import flash.filters.GlowFilter;
    import flash.geom.Matrix;
    import flash.geom.PerspectiveProjection;
    import flash.geom.Point;
    
    [SWF(backgroundColor="#000000", frameRate="60")]
    public class ForkedStuff extends Sprite {
        public static const WIDTH:int = 465;
        public static const HEIGHT:int = 465; 
        public static const MAX_RADIUS:int = 220;
        public static const PARTICLES:int = 1000;
        private var bmp:Bitmap = new Bitmap( new BitmapData(WIDTH, HEIGHT, false, 0x0)); // screen
        private var particles:Array = [];
        private var _glow:Bitmap = new Bitmap(new BitmapData(WIDTH / 4, HEIGHT / 4, false, 0xffffff), PixelSnapping.NEVER, true); // glow
        private var _glowMtx:Matrix;
        private var __container:Sprite = new Sprite();
        private var __center:Sprite = new Sprite();
        public function ForkedStuff() {        
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;                    
            _glow.scaleX = _glow.scaleY = 4;
            _glow.blendMode = BlendMode.ADD;
            _glowMtx = new Matrix(0.25 ,0, 0, 0.25);        
            for(var i:int=0; i<PARTICLES; i++){
                var p:Particle = new Particle();
                p.theta = Math.random() * 360;
                p.radius = (MAX_RADIUS - i*MAX_RADIUS/PARTICLES);
                p.x = p.radius * Math.cos(p.theta * Math.PI / 180) + (465 / 2);
                p.y = p.radius * Math.sin(p.theta * Math.PI / 180) + (465 / 2);
                p.color = i%2 ? 0x00aeef :0xec008c;
                p.speed = 0.5+Math.random()/3;
                particles[i] = p;
            }
            __container.addChild(bmp);            
            __container.addChild(_glow);
            __center.x = __container.x = WIDTH/2;
            __center.y = __container.y = HEIGHT/2;
            bmp.x =_glow.x = -WIDTH/2;
            bmp.y =_glow.y = -HEIGHT/2;            
            addChild(__container);
            with(__center.graphics){
                beginFill(0xCCCCFF,.8);
                drawCircle(0,0,4);
                endFill();
            }
            __center.filters = [new GlowFilter(0xCCCCFF,1,12,12,3,3)];
            addChild(__center);
            stage.addEventListener(MouseEvent.MOUSE_MOVE,__onMouseMove);
            stage.addEventListener(MouseEvent.CLICK,__onMouseClick);
            stage.addEventListener(Event.RESIZE,__onResize);
            stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        
        private function __onResize($e:Event):void{
            if(stage == null || stage.stageWidth == 0 || stage.stageHeight == 0)return;
            var pp:PerspectiveProjection = new PerspectiveProjection();
            pp.projectionCenter = new Point(stage.stageWidth/2,stage.stageHeight/2);            
            transform.perspectiveProjection = pp;
            __center.x = __container.x =stage.stageWidth/2;
            __center.y = __container.y =stage.stageHeight/2;            
        }
        
        private function __onMouseClick($e:MouseEvent):void{
                __explode = true;        
        }
        
        private function __onMouseMove($e:MouseEvent):void{
            if(stage==null || stage.stageWidth == 0 || stage.stageHeight == 0)return;
            __container.rotationY = 65*Math.min(1,Math.max(-1,(((stage.stageWidth-stage.mouseX)-stage.stageWidth/2)/(stage.stageWidth/2))));
            __container.rotationX = 65*Math.min(1,Math.max(-1,(((stage.stageHeight-stage.mouseY)-stage.stageHeight/2)/(stage.stageHeight/2))));
            $e.updateAfterEvent();
        }
        
        public function enterFrameHandler(e:Event):void{
            __render();
        }
        
        private var __explode:Boolean = false;
        private function __render():void{
            bmp.bitmapData.lock(); // lock bmp
            var maxRadius:Number = 0;
            for(var i:int=0; i<particles.length; i++){
                var p:Particle = particles[i];
                p.theta += 2;
                if(__explode){
                    p.radius = (p.radius <= MAX_RADIUS) ? p.radius + p.speed:MAX_RADIUS;
                    if(p.radius >= MAX_RADIUS){
                        __explode = false;
                        for(var k:int=0; k<particles.length; k++){
                            particles[k].speed = 0.5+Math.random()/3;
                        }                        
                    }
                }else{
                    p.radius = (p.radius >= 0) ? p.radius - p.speed:0;
                    maxRadius = Math.max(maxRadius,p.radius);
                }
                p.x = p.radius * Math.cos((p.theta) * Math.PI / 180) +WIDTH/2;
                p.y = p.radius * Math.sin((p.theta) * Math.PI / 180) +HEIGHT/2;                
                bmp.bitmapData.setPixel(p.x, p.y, p.color);
            }
            if(!__explode && maxRadius<=1){
                for(var n:int=0; n<particles.length; n++){
                    particles[n].speed = 1+Math.random();
                }
                __explode=true
            }
            bmp.bitmapData.unlock();
            _glow.bitmapData.draw(bmp.bitmapData, _glowMtx); // Draw glow
            bmp.bitmapData.applyFilter(bmp.bitmapData,bmp.bitmapData.rect,new Point(),new BlurFilter(1.1,1.1,3));
        }
    }
}

class Particle {
    public var x:Number; // X
    public var y:Number; // Y
    public var speed:Number;
    public var theta:Number; // theta
    public var radius:Number;
    public var color:uint; // particle color
}