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

HeavyRain forked from: Waterfall

Get Adobe Flash player
by yamadori 22 May 2010
/**
 * Copyright yamadori ( http://wonderfl.net/user/yamadori )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wda4
 */

// 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;
    import net.hires.debug.Stats;
    
	[SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
    public class Waterfall extends Sprite {
        private var cvs:BitmapData;     
        private var particles:Array = [];
        private var h:int = stage.stageHeight;
        private var w:int = stage.stageWidth;
        private var h4:int = Math.round(h/4);
        private var c:uint = 0xff81ABD5;
        private var theta:Number = 0;
        private var blur:BlurFilter;

        public function Waterfall(){
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.LOW;
            
        	    blur = new BlurFilter(14,14,1);
            cvs = new BitmapData(w,h,true,0);
            addChild(new Bitmap(cvs)) as Bitmap;
            addEventListener(Event.ENTER_FRAME,update);
            addChild(new Stats());
        }
        
        private function update(e:Event):void {
			cvs.lock();
			n = 20;
			var a:Number = 5;
			var b:Number = .1;
			while (n--) {
				createParticle( Math.random()*w, 0, c, 0, Math.sin(theta)+a*Math.random()-b );
			}
			cvs.applyFilter(cvs,cvs.rect,new Point(),blur);
			var n:int = particles.length;
			while (n--) {
				var p:Particle = particles[n];
				p.vx*=0.99;
				p.vy*=1.01;
				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 || p.vy<0.05) {
					particles.splice(n,1);
				}
				if (p.y>h*0.9) {
					p.vy*=0.8;
					p.vx=0;
				}
			}
			cvs.unlock();
		}

		private function createParticle(xx:Number, yy:Number, c:int, vx:Number, vy:Number ):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;
}