forked from: Mandelbrot fractal using palette

by hacker_nmyze_52 forked from Mandelbrot fractal using palette (diff: 35)
Now it uses a palette for rendering. FAST!
♥0 | Line 46 | Modified 2009-11-12 06:41:51 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_nmyze_52 ( http://wonderfl.net/user/hacker_nmyze_52 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/faa5
 */

// forked from splashdust's Mandelbrot fractal using palette
// forked from splashdust's Mandelbrot fractal
// Now it uses a palette for rendering. FAST!
package {
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.utils.Timer;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.geom.Point;
    
    [SWF(width="512", height="512", frameRate="15")]
    
    public class FlashTest extends Sprite {
        public static var width:int = 512;
        public static var height:int = 512;
        public function FlashTest() {
           var setBitmap:Bitmap = new Bitmap();
            var bitmapData:BitmapData = new BitmapData( stage.stageWidth , stage.stageHeight , false , 0x000000 );
            
            setBitmap.bitmapData = bitmapData;

            addChild( setBitmap );
            
            var beforeTime:int = flash.utils.getTimer();
            var xtemp:Number = 0;
            var x0:Number = 0;
            var y0:Number = 0;
            var iteration:int = 0;
            
            for(var ix:int=0; ix<width; ix++) {
	            for(var iy:int=0; iy<height; iy++) {
			
			x0 = 0;
			y0 = 0;
			iteration = 128;
			
			while ( x0*x0 + y0*y0 <= 4  &&  iteration > 0 ) 
  			{
				xtemp = x0*x0 - y0*y0 + (ix-14*5000)/50000;
				y0 = 2*x0*y0 + (iy-(height/0.6))/50000;
				x0 = xtemp;
				
				iteration--;
			}
			
			bitmapData.setPixel(ix, iy, iteration);
		}
            }

            var afterTime = flash.utils.getTimer();

            var tf = new TextField();
            tf.width = 400;
            tf.text = "Generating fractal took "+(afterTime-beforeTime)+" ms";
            addChild(tf);
        }
    }
}