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

Fountain

Get Adobe Flash player
by termat 04 Sep 2010
    Embed
/**
 * Copyright termat ( http://wonderfl.net/user/termat )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cjB2
 */

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.geom.Rectangle;
    import flash.utils.Timer;

    [SWF(width = "430", height = "430", backgroundColor = "0x000000", fps = "30")]
    public class Practice96 extends Sprite{
        private var bitmap:BitmapData;
        private var col:Array = new Array();
        private var px:Array = new Array();
        private var p:Array = new Array();
        private var num:int = 200;
        private var maxX:Number;
        private var maxY:Number;
        private var zz:int;
        private var timer:Timer;
        
        public function Practice96() {
            for (var i:int=0;i<256;i++)
            col[i] = (Math.min(255, 10 * (i / 8)) << 16) +
                    (Math.min(255, 10 * (i / 4)) << 8) + Math.min(255, 10 * i );
            bitmap = new BitmapData(430, 430, false, 0x000000);
            addChild(new Bitmap(bitmap));
            addEventListener(Event.ENTER_FRAME, update);
            setupParam();
            for (i = 0; i < num; i++) p.push(initParticle(new Particle()));
            timer = new Timer(5000);
            timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void { setupParam(); } );
            timer.start();
        }
        
        private function setupParam():void {
            maxX= Math.random() * 5 + 0.5;
            maxY = Math.random() * 6 + 3;
        }
        
        private function initParticle(p:Particle):Particle {
            p.vx = Math.random() * maxX - maxX / 2;
            p.vy = -Math.random() * maxY - maxY / 2;
            p.x = bitmap.width/2;
            p.y = bitmap.height;
            return p;
        }
        
        private function update(e:Event):void {
            var w:Number = bitmap.width;
            var h:Number = bitmap.height;
            bitmap.fillRect(bitmap.rect, 0x000000);
            var h2:int = w * (h - 2);
            for (var i:int = 0; i < h; i++) px[h2 + i] = 0;
            for (i = 0; i < 200; i++) px[h2 + Math.floor(Math.random() * w)] = 255;
            for (i = 0; i < p.length; i++) {
                if(p[i].y>h+5)initParticle(p[i]);
                p[i].x += p[i].vx;
                p[i].y += p[i].vy;
                p[i].vy += 0.2;
                var d:int = w * Math.floor(p[i].y) + Math.floor(p[i].x);
                if (p[i].x > 1 && p[i].x < w - 2 && p[i].y > 1 && p[i].y < h - 1){
                    px[d] = px[d + 1] = px[d + 1 + w] = px[d + w] = Math.floor(Math.random()*100) % 22 + 200;
                }
            }
            for (var yy:int = 1; yy < h - 2; yy++) {
                var py:int = w * yy;
                for (var xx:int = 1; xx < w - 1; xx++) {
                    var pt:int = py + xx;
                    px[pt] = (px[pt - w] + px[pt + w]
                        +px[pt + 1] + px[pt - 1]) >> 2;
                    bitmap.setPixel(xx, yy, col[px[pt - w]]);
                }
            }
        }
    }
}

class Particle {
    public var x:Number = 0;
    public var y:Number = 0;
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var col:uint;
}