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 galaxy

So I wanted to make it even more colorful and make it more like a moving fractal then tracer as previous one.

Controls:
Drag with mouse
Zoom with mouse wheel
Clear and change colors with double click

Considering it finished for now, thinking on making bigger, more optimized version with interface and a lot of options to play with like I made here http://wonderwhy-er.deviantart.com/art/Rainbow-Whirls-2-0-76544660
// forked from wonderwhyer's Mandelbrot orbits storm
// forked from makc3d's Mandelbrot orbits

    //****************************
    //Controls
    //Controls:
    //Drag with mouse
    //Zoom with mouse wheel
    //Clear and change colors with double click
    //****************************
    
package  {
    import flash.geom.Rectangle;
    import flash.geom.Matrix;
    import flash.filters.BlurFilter;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.display.BlendMode;
    

    
    [SWF(width=465,height=465)]
    public class MandelbrotOrbits extends Sprite {
        public var b:Bitmap;
        public var bd:BitmapData;
        public var ct:ColorTransform;
        public var xy0:Vector.<Point>;
        public var xyi:Vector.<Point>;
        public var alphas:Vector.<Number>;
        public var colors:Vector.<uint>;
        public var splines:Vector.<Spline2D>;
        
        public var colorMap:BitmapData = new BitmapData(465,465,false,0);
        
        public var blur:BlurFilter = new BlurFilter(1.5,1.5,3);
        public var sp:Sprite = new Sprite()
        private var mDown:Boolean = false;
        
        
        
        public function MandelbrotOrbits () {
            bd = new BitmapData (465, 465, false, 0);
            addChild (b = new Bitmap (bd));
            ct = new ColorTransform (0.88, 0.92, 0.97, 1, 0, 0, 0);
            xy0 = new Vector.<Point> (3);
            alphas = new Vector.<Number>(xy0.length);
            colors = new Vector.<uint>(xy0.length);
            xyi = new Vector.<Point> (xy0.length);
            splines = new Vector.<Spline2D> (xy0.length);
            for (var i:int = 0; i < xy0.length; i++) {
                xy0 [i] = new Point (
                    2 * Math.random () - 0.5,
                    2 * Math.random () - 1.0
                );
                xyi [i] = xy0 [i].clone ();
                splines [i] = new Spline2D (xy0 [i]);
                alphas[i]=1;
            }
            colorMap.perlinNoise(30,30,3,Math.random()*uint.MAX_VALUE,false,false);
            stage.addEventListener (Event.ENTER_FRAME, draw);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,down);
            stage.addEventListener(MouseEvent.MOUSE_UP,up);
            stage.doubleClickEnabled=true;
            stage.addEventListener(MouseEvent.DOUBLE_CLICK,dclick);
            stage.addEventListener(MouseEvent.MOUSE_WHEEL,wheel);
        }
        
        public function wheel(e:MouseEvent):void{
            if(e.delta<0){
                m.a*=0.9;
            }else{
                m.a/=0.9;
            }
            m.d=m.a;
        }

        
        public function dclick(e:Event):void{
            bd.fillRect(bd.rect,0);
            colorMap.perlinNoise(30,30,3,Math.random()*uint.MAX_VALUE,false,false);
        }

        
        public function up(e:Event):void{
            mDown=false;
        }

        public function down(e:Event):void{
            mDown=true;
        }
        
        private var mlx:Number = mouseX;
        private var mly:Number = mouseY;
        private var xx:Number = 0;
        private var yy:Number = 0;
        private var m:Matrix = new Matrix(1,0,0,1,200,0);
        
        
        
        public function draw (e:Event):void {
            createParticle();
            sp.graphics.clear ();
            
            if(mDown){
                m.tx+=mouseX-mlx;
                m.ty+=mouseY-mly;
            }
            mlx=mouseX;
            mly=mouseY;
            
            for (var i:int = 0; i < xy0.length; i++) {
                var z:Point = xyi [i];
                var aa:Number = z.x * z.x;
                var bb:Number = z.y * z.y;
                if(alphas[i]<0){
                    removeParticle(i);
                    i--;
                    continue;
                }else{
                    alphas[i]-=0.03;
                }
                if (aa + bb < 4) {
                    var ab:Number = z.x * z.y;
                    var xx:Number = aa - bb;
                    var yy:Number = 2 * ab;
                    //direction.normalize(0.3);
                    var xi:Number =  xx+ xy0 [i].x;
                    var yi:Number =  yy+ xy0 [i].y;
                    if ((z.x - xi)*(z.x - xi) + (z.y - yi)*(z.y - yi) > 1e-6) {
                        sp.graphics.lineStyle(0, colors[i],alphas[i]);
                        z.x = xi; z.y = yi; 
                        splines [i].addNextPoint (z, sp.graphics);
                    } else {
                        removeParticle(i);
                        i--;
                    }
                } else {
                    removeParticle(i);
                    i--;
                }
            }
            sp.visible=false;
            bd.draw(sp,m,null,BlendMode.ADD);
            bd.applyFilter(bd,bd.rect,bd.rect.topLeft,blur);
        }
        
       

        public function removeParticle(i:uint):void{
            xy0.splice (i, 1);
            xyi.splice (i, 1);
            splines.splice (i, 1);
            alphas.splice(i,1);
            colors.splice(i,1);
        }

        public function createParticle ():void {
            for(var i:int=0;i<5;i++){
                var newP:Point = new Point (
                    (Math.random()*2- 0.5-m.tx/232)/m.a,
                    (Math.random()*2- 1.0-m.ty/232)/m.a
                );
                xy0.push (newP);
                xyi.push (newP.clone ());
                splines.push (new Spline2D (newP));
                alphas.push(1);
                colors.push(colorMap.getPixel((newP.x+0.5*232),(newP.y+1)*232));
            }
        }
    }
}

import flash.display.Graphics;
import flash.geom.Point;
class Spline2D {
    public var points:Vector.<Point>
    public function Spline2D (p:Point) {
        points = new Vector.<Point>;
        for (var i:int = 0; i < 4; i++) points.push (p.clone ());
    }
    public function addNextPoint (p:Point, g:Graphics):void {
        points.shift (); points.push (p.clone ());
        // draw previous segment
        g.moveTo (465 * (0.5 + points [1].x) / 2, 465 * (1.0 + points [1].y) / 2);
        for (var i:int = 1; i < 11; i++) {
            p = spline (points [0], points [1], points [2], points [3], 0.1 * i);
            g.lineTo (465 * (0.5 + p.x) / 2, 465 * (1.0 + p.y) / 2);
        }
    }
    /* 
    * Calculates 2D cubic Catmull-Rom spline.
    * @see http://www.mvps.org/directx/articles/catmull/ 
    */ 
    private function spline (p0:Point, p1:Point, p2:Point, p3:Point, t:Number):Point {
        return new Point (
            0.5 * ((          2*p1.x) +
                t * (( -p0.x           +p2.x) +
                t * ((2*p0.x -5*p1.x +4*p2.x -p3.x) +
                t * (  -p0.x +3*p1.x -3*p2.x +p3.x)))),
            0.5 * ((          2*p1.y) +
                t * (( -p0.y           +p2.y) +
                t * ((2*p0.y -5*p1.y +4*p2.y -p3.y) +
                t * (  -p0.y +3*p1.y -3*p2.y +p3.y))))
        );
    }
}