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: Mandelbrot

Mandelbrot power from Perlin noise
Get Adobe Flash player
by makc3d 14 Mar 2011
// forked from rect's Mandelbrot
package
{
    import flash.events.Event;
    import flash.display.*;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.utils.getTimer;
    import flash.utils.ByteArray;

    [SWF(backgroundColor="#000000")]
    
    public class main extends Sprite
    {
        private var w:uint = 465;
        private var h:uint = 465;
        private var maxIteration:int = 20;

        public function main():void
        {
            var bmp:BitmapData = new BitmapData(w, h, false, 0x000000);
            addChild (new Bitmap (bmp));

			var pn:BitmapData = bmp.clone ();
			pn.perlinNoise (64, 64, 4, 256 * Math.random (), true, true, 7, true);

            var bytes:ByteArray = new ByteArray();
            bytes.position = 0;
            var pixels:uint = w * h;

            for (var j:int = 0; j < pixels; j++)
            {
                var x:int = (j % w) >> 0;
                var y:int = (j / w) >> 0;
                var pr:Number = (x - w / 2) / 200;
                var pi:Number = (y - h / 2) / 200;
				// set Mandelbrot power from Perlin noise
				var p:Number = 2 + 1 * (255 & pn.getPixel (x, y)) / 255;
                var newRe:Number = 0;
                var newIm:Number = 0;
                var i:int = 0;
                for(i= 0; i < maxIteration; i++)
                {
					// r^p
					var rp:Number = Math.pow (newRe * newRe + newIm * newIm, p / 2);
					// theta*p
					var tp:Number = Math.atan2 (newIm, newRe) * p;
					// z^p = r^p(cos(theta*p)+isin(theta*p))
					// z = z^p + c
                    newRe = rp * Math.cos (tp) + pr;
                    newIm = rp * Math.sin (tp) + pi;
                    if((newRe * newRe + newIm * newIm) > 4) break;
                }
                var rgb:uint = 0x10101 * int (255 * i / maxIteration);

                bytes.writeUnsignedInt(rgb);
            }

            bytes.position = 0;
            bmp.setPixels(bmp.rect, bytes);
        }
    }
}