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

Mandelbrot II

Mandelbrot II
Get Adobe Flash player
by rect 24 May 2009
/**
 * Copyright rect ( http://wonderfl.net/user/rect )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uaUD
 */

//
// Mandelbrot II
//
package
{
    import flash.events.Event;
    import flash.display.*;
    import flash.utils.getTimer;

    [SWF(backgroundColor="#000000",width="465", height="465")]
    
    public class main extends Sprite
    {
        private const toRadian:Number = Math.PI/180;
        private var w:uint = 128;
        private var h:uint = 128;
        private const pixels:uint = w * h;
        private var image:Bitmap;

        private var zoom:Number = 0.2;
        private var mx:Number = 0.38799;
        private var my:Number = 0.2599;
        private var maxIteration:int = 128;
        

        public function main():void
        {
            stage.frameRate = 30;
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.LOW;

            var bmp:BitmapData = new BitmapData(w, h, false, 0x00000000);
            image = new Bitmap(bmp);
            addChild(image);
            image.width = stage.stageWidth;
            image.height = stage.stageHeight;
            image.x = (stage.stageWidth - image.width) / 2;
            image.y = (stage.stageHeight - image.height) / 2;

            addEventListener(Event.ENTER_FRAME, update);
        }

        private function update(e:Event):void
        {
            var targetBmd:BitmapData = image.bitmapData;
            var newRe:Number = 0, newIm:Number = 0, oldRe:Number = 0, oldIm:Number = 0;
            var i:int, j:int;
            if(zoom > 54000) zoom = 0.2;
            zoom += zoom * 0.01;
            mx -= 1 / zoom *0.00001;
            my = 0.2599;

            targetBmd.lock();
            for (j = 0; j < pixels; j++)
            {
                var x:int = int(j % w);
                var y:int = int(j / w);
                var pr:Number = 1.5 * (x - w * 0.5) / (0.7 * zoom * w) + mx;
                var pi:Number = (y - h * 0.5) / (0.5 * zoom * h) + my;
                newRe = newIm = oldRe = oldIm = 0;
                for(i = 0; i < maxIteration; i++)
                {
                    oldRe = newRe;
                    oldIm = newIm;
                    newRe = oldRe * oldRe - oldIm * oldIm + pr;
                    newIm = 2 * oldRe * oldIm + pi;
                    if((newRe * newRe + newIm * newIm) > 4) break;
                }
                var rgb:int = i*38 << 16 | i*64 << 8 | i*8;
                targetBmd.setPixel(x,y,rgb);
            }
            targetBmd.unlock();
        }
    }
}