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

Space Comet

/**
 * Copyright Hasufel ( http://wonderfl.net/user/Hasufel )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6Di1
 */

package {

    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import net.hires.debug.Stats;
    
[SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
    public class spaceComet extends Sprite {
        private var cvs:BitmapData;        
        private var particles:Array = [];
        private var stars:Array = [];
        private var cols:Array = [0xffffffff,0xffffcdff,0xffbebebe,0xffc7c7c7,0xffaaaaaa];
        private var h:int = stage.stageHeight;
        private var w:int = stage.stageWidth;
        private var w2:int = Math.round(w/2);
        private var h2:int = Math.round(h/2);
        private var c:uint = 0xffffcc00;
        private var theta:Number = 0;
        private var blur:BlurFilter;


        public function spaceComet(){
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.LOW;
            var blackBg:Bitmap = new Bitmap(new BitmapData(465,465,false,0x000000));
            addChild(blackBg);
            addChild(new Stats());
            blur = new BlurFilter(14,14,1);
            cvs = new BitmapData(w,h,true,0);
            addChild(new Bitmap(cvs)) as Bitmap;
            addEventListener(Event.ENTER_FRAME,update);
        }
        
        private function update(e:Event):void{
            cvs.applyFilter(cvs,cvs.rect,new Point(0,0),blur);
            cvs.lock();
            var n:int = particles.length;
            while(n--) {
                var p:Particle = particles[n];
                p.vx*=1.1;
                p.vy*=1.1;
                p.x+=p.vx;
                p.y+=p.vy;
                cvs.setPixel32(p.x,p.y,p.c);
                if (p.y<0 || p.y>h || p.x<0 || p.x>w){
                    particles.splice(n,1);
                }
            }
            var o:int = stars.length;
            while(o--) {
                var s:Particle = stars[o];
                s.x+=s.vx*=1.03;
                s.y+=s.vy*=1.03;
                cvs.setPixel32(s.x,s.y,s.c);
                if (s.y<0 || s.y>h || s.x<0 || s.x>w){
                    stars.splice(o,1);
                }
            }
            cvs.unlock();
            n = 100;
            while (n--) {
                createParticle(w2,h2,c,Math.cos(theta)+.8*Math.random()-.1,Math.sin(theta)+.8*Math.random()-.1,true);
            }
            o=20;
            while (o--) {
                createParticle(Math.random()*w,Math.random()*h,cols[randomNumber(0,4)],Math.cos(theta)+.1*Math.random()-.1,Math.sin(theta)+.1*Math.random()-.1,false);
            }
            theta+=.005;
        }

        private function createParticle(xx:Number, yy:Number, c:int, vx:Number, vy:Number, type:Boolean):void {
            var p:Particle = new Particle();
            p.x = xx;
            p.y = yy;
            p.vx = vx;
            p.vy = vy;
            p.c = c;
            if (type) {particles.push(p);} else {stars.push(p);}
        }

        private function randomNumber(low:int, high:int):int{
            return Math.round(Math.random() * (high - low) + low);
        }


    }
}

class Particle {
    public var x:Number;
    public var y:Number;
    public var vx:Number;
    public var vy:Number;
    public var c:uint;
}