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

Mixedbrot

Paint power map, then render.
Black pixels are for 2nd power, white are for 3rd.
// forked from makc3d's forked from: Mandelbrot
// forked from rect's Mandelbrot
package
{
	import com.bit101.components.PushButton;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;

    import flash.events.Event;
    import flash.display.*;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.utils.*;

   
    public class main extends Sprite
    {
        private var w:uint = 465;
        private var h:uint = 465;
        private var maxIteration:int = 20;
		private var bytes:ByteArray;
		private var bmp:BitmapData, pn:BitmapData;
		private var brush:Sprite = new Sprite;

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

            bytes = new ByteArray ();
			stage.addEventListener (MouseEvent.MOUSE_DOWN, watchMouse);
			stage.addEventListener (MouseEvent.MOUSE_UP, watchMouse);
			stage.addEventListener (MouseEvent.MOUSE_MOVE, draw);

			var m:Matrix = new Matrix;
			m.createGradientBox (80, 80, 0, -40, -40);
			brush.graphics.beginGradientFill ("radial", [0xFFFFFF, 0xFFFFFF], [0.2, 0], [0, 255], m);
			brush.graphics.drawCircle (0, 0, 40);

			new PushButton (this, 10, 10, "RENDER", render);
		}

		private var mouseDown:Boolean;
		private function watchMouse (e:MouseEvent):void {
			mouseDown = (e.type == MouseEvent.MOUSE_DOWN); draw (e);
		}

		private function draw (e:MouseEvent):void {
			brush.x = mouseX; brush.y = mouseY;
			if (mouseDown) bmp.draw (brush, brush.transform.matrix);
		}

		private function render (e:Event):void {
			e.target.visible = false;
			stage.removeEventListener (MouseEvent.MOUSE_DOWN, watchMouse);
			stage.removeEventListener (MouseEvent.MOUSE_UP, watchMouse);
			stage.removeEventListener (MouseEvent.MOUSE_MOVE, draw);

			pn = bmp.clone ();

            bytes.position = 0;
            var pixels:uint = w * h;
			var zoom:Number = 3 / h;

            for (var j:int = 0; j < pixels; j++)
            {
                var x:int = j / w;
                var y:int = j % w;
                var pr:Number = (x - h / 2) * zoom - 0.5;
                var pi:Number = (y - w / 2) * zoom;
				// set Mandelbrot power from Perlin noise
				var k:Number = (255 & pn.getPixel (y, x)) / 255;
				var p:Number = 2 + k; 
                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);
       }
    }
}