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 orbits storm

Just wanted there to be more of it :)
So made 5 of those spawn at each frame if mouse is held down. 
Also as a precaution of many cycling particles made them live for 100 frame fading away slowly.
// forked from makc3d's Mandelbrot orbits
// click to launch particle
package  {
    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 splines:Vector.<Spline2D>;
        
        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);
            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;
            }
            stage.addEventListener (Event.ENTER_FRAME, draw);
            stage.addEventListener (MouseEvent.MOUSE_DOWN, down);
            stage.addEventListener (MouseEvent.MOUSE_UP, up);
        }
        public function draw (e:Event):void {
            if(mDown)createParticle();
            graphics.clear (); 
            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.01;
                }
                if (aa + bb < 4) {
                    var ab:Number = z.x * z.y;
                    var xi:Number = aa - bb + xy0 [i].x;
                    var yi:Number = 2 * ab + xy0 [i].y;
                    if ((z.x - xi)*(z.x - xi) + (z.y - yi)*(z.y - yi) > 1e-6) {
                        graphics.lineStyle(0, 0xffffff,alphas[i]);
                        z.x = xi; z.y = yi; splines [i].addNextPoint (z, graphics);
                    } else {
                        removeParticle(i);
                        i--;
                    }
                } else {
                    removeParticle(i);
                    i--;
                }
            }
            b.visible = false; bd.draw(this,null,null,BlendMode.ADD); b.visible = true;
            bd.colorTransform (bd.rect, ct);
        }
        
        public function down(e:Event):void{
            mDown = true;
        }
        public function up(e:Event):void{
            mDown = false;
        }        

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

        public function createParticle ():void {
            for(var i:int=0;i<10;i++){
                var newP:Point = new Point (
                    2 * (mouseX+(Math.random()-0.5)*5) / 465 - 0.5,
                    2 * (mouseY+(Math.random()-0.5)*5) / 465 - 1.0
                );
                xy0.push (newP);
                xyi.push (newP.clone ());
                splines.push (new Spline2D (newP));
                alphas.push(1);
            }
        }
    }
}

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))))
        );
    }
}