Pole

by jerryrom forked from Waterfall (diff: 21)
♥0 | Line 74 | Modified 2010-03-30 06:20:39 | MIT License
play

ActionScript3 source code

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

// forked from jerryrom's Waterfall
// forked from Hasufel's Space Comet
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;
    
[SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
    public class Pole extends Sprite {
        private var cvs:BitmapData;     
        private var particles:Array = [];
        private var h:int = stage.stageHeight;
        private var w:int = stage.stageWidth;
        private var w2:int = Math.round(w/2);
        private var w3:int = Math.round(w/3);
        private var c:uint = 0xff81ABD5;
        private var theta:Number = 0;
        private var blur:BlurFilter;

        public function Pole(){
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.LOW;
            graphics.beginFill(0x000000);
        	    graphics.drawRect(0, 0, 465, 465);
        	    graphics.endFill();
        	    
            blur = new BlurFilter(0,5,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.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);
                }
            }
            cvs.unlock();
            n = 20;
            var a:Number = 10;
            while (n--) {
                createParticle(w3, Math.random()*h, c , a*Math.random(), a,true);
                createParticle(w3*2, Math.random()*h, c , -a*Math.random(), a,true);
            }
            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;
            particles.push(p);
        }
    }
}

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

Forked