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: dripping, distorting

Get Adobe Flash player
by bradsedito 21 Feb 2011
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3wOH
 */

// forked from k__'s dripping, distorting
package {
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    
    public class Main extends Sprite {
    
        private var space:Sprite;
        private var floor:BitmapData;
        private var noise:BitmapData;
        private var brush:Sprite;
        private var bobbles:Array;
        private var cx:Number, cy:Number;
        private var msx:Number, msy:Number;
        private var fils:Array;
        private var cnt:uint = 0;
        
        
        public function Main() {
            addChild(new Bitmap(floor = new BitmapData(stage.stageWidth, stage.stageHeight)));
            addChild(space = new Sprite());
            brush = new Sprite();
            bobbles = [];
            stage.addEventListener(MouseEvent.MOUSE_MOVE, h_mouseMove);
            addEventListener(Event.ENTER_FRAME, h_enterFrame);
            msx = cx = stage.stageWidth / 2;
            msy = cy = stage.stageHeight / 2;
            space.filters = [new BlurFilter()];
            fils = [];
            fils.push(new ColorMatrixFilter([1.008,0,0,0,0, 0,1.008,0,0,0, 0,0,1.004,0,0, 0,0,0,1,0]));
            
            noise = new BitmapData(stage.stageWidth, stage.stageHeight);
            noise.perlinNoise(100,100,4,1,true,true);
            fils.push(new DisplacementMapFilter(noise,null,BitmapDataChannel.GREEN,BitmapDataChannel.RED,1,1));
        }
        
        private function h_enterFrame(evt:Event):void {
            update();
        }
        
        private function h_mouseMove(evt:MouseEvent):void {
            for (var i:uint = 0; i < 5; i ++) {
                var b:Object = {};
                var r:Number = Math.random() * Math.PI * 2;
                var d:Number = Math.random() * 5;
                b.vx = Math.cos(r) * d + (mouseX - msx) / 10;
                b.vy = Math.sin(r) * d + (mouseY - msy) / 10;
                b.vz = Math.random() * 8;
                b.x = mouseX - cx + b.vx;
                b.y = mouseY - cy + b.vy;
                b.z = 0;
                b.col = Math.floor(0x232323);
                b.size = Math.random() * 5;
                bobbles.push(b); 
            }
            
            msx = mouseX;
            msy = mouseY;
        }
        
        private function update():void {
            var temp:Array = bobbles.concat();
            temp.sortOn(z);
            bobbles = new Array();
            space.graphics.clear();
            space.graphics.clear();
            for (var i:uint = 0; i < temp.length; i ++) {
                temp[i].vz -= 0.5;
                temp[i].x += temp[i].vx;
                temp[i].y += temp[i].vy;
                temp[i].z += temp[i].vz;
                draw(space.graphics, temp[i], (1 - (temp[i].z +20) / 30));
                if (temp[i].z > -20) {
                    bobbles.push(temp[i]);
                } else {
                    brush.graphics.clear();
                    draw(brush.graphics, temp[i], 0.9);
                    floor.draw(brush, null, null,BlendMode.DARKEN);
                }
            }
            
            for (i = 0; i < fils.length; i ++) {
                floor.applyFilter(floor, floor.rect, new Point(0,0), fils[i]);
            }
        }
        
        private function draw(g:Graphics, b:Object, a:Number):void {
            var scale:Number = (b.z + 200) / 200;
            g.beginFill(b.col,a);
            g.drawCircle(cx + b.x * scale, cy + b.y * scale, b.size * scale);
            g.endFill();
        }
        
    }
}