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 flow

click to launch particle
Get Adobe Flash player
by bradsedito 23 Nov 2010
// forked from wonderwhyer's Mandelbrot flow
// forked from wonderwhyer's Mandelbrot orbits storm
// forked from makc3d's Mandelbrot orbits
// click to launch particle
package  {
    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;
    import gs.*;
    import gs.easing.*;
     
    
    
    [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(1000,600,true,1);
        
        public var blur:BlurFilter = new BlurFilter(4,4,3);
        
        private var mDown:Boolean = false;
        

       
        public function MandelbrotOrbits () {
            bd = new BitmapData (1000, 600, true, 1);
            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]=0;
            }
            colorMap.perlinNoise(30,30,3,Math.random()*uint.MAX_VALUE,false,false);
            stage.addEventListener (Event.ENTER_FRAME, draw);
            
         
        }
        public function draw (e:Event):void {
            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;
                
       TweenMax.to(this, .5, {x:mouseX})

                
                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) {
                        graphics.lineStyle(0, colors[i],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.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<10;i++){
                var newP:Point = new Point (
                    Math.random()*2- 0.5,
                    Math.random()*2- 1.0
                );
                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))))
        );
    }
}