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: flash on 2012-12-1

Get Adobe Flash player
by yonatan 01 Dec 2012
/**
 * Copyright yonatan ( http://wonderfl.net/user/yonatan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dok7
 */

// forked from yonatan's flash on 2012-12-1
package {
    import flash.display.*;
    import flash.events.*;

    public class main extends Sprite {
        private var bmd:BitmapData = new BitmapData(465, 465, false, 0);
        private var bmp:Bitmap = new Bitmap(bmd);
        private var _x:int = 0, _y:int = 0;
        private var balls:Array = [];
        

        function main():void {
            balls.push(new Ball(-100,-100));
            balls.push(new Ball(150,0));
            balls.push(new Ball(0,150));
            addChild(bmp);
            addEventListener("enterFrame", frame);
        }

        private function frame(e:Event):void {
            for(var i:int = 0; i < 10000; i++) tick();
        }

        private function tick():void {
            var dir:int = Math.random()*4;
            var v:int = 0;
            for each(var b:Ball in balls) {
                switch(dir) {
                    case 0: if(_y>-200) { b.dsq = b.dsq - b.y - b.y + 1; b.y--; } break;
                    case 1: if(_x< 200) { b.dsq = b.dsq + b.x + b.x + 1; b.x++; } break;
                    case 2: if(_y< 200) { b.dsq = b.dsq + b.y + b.y + 1; b.y++; } break;
                    case 3: if(_x>-200) { b.dsq = b.dsq - b.x - b.x + 1; b.x--; } break;
                }
                v += 0xffffff/Math.sqrt(b.dsq);
            }
            switch(dir) {
                case 0: if(_y>-200) _y--; break;
                case 1: if(_x< 200) _x++; break;
                case 2: if(_y< 200) _y++; break;
                case 3: if(_x>-200) _x--; break;
            }
            bmd.setPixel(232+_x, 232+_y, v);
        }
    }
}

class Ball {
    public var x:int, y:int, dsq:int;
    public function Ball(x_:int, y_:int) {
        x = x_;
        y = y_;
        dsq = x*x + y*y;
    }
}