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

Fractal - フラクタル

Get Adobe Flash player
by cpu_t 24 Jun 2010
    Embed
/**
 * Copyright cpu_t ( http://wonderfl.net/user/cpu_t )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lWLM
 */

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;

    public class FlashTest extends Sprite
    {
        public function FlashTest()
        {
            canvas=new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
            addChild(new Bitmap(canvas));
            ctrans=new ColorTransform(0.98,0.98,0.98);
            bfilter=new BlurFilter(2,2);
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN,mdHandler);
        }
        
        private var canvas:BitmapData;
        private var bfilter:BlurFilter;
        private var ctrans:ColorTransform;
        
        public function mdHandler(e:MouseEvent):void
        {
            canvas.lock();
            canvas.colorTransform(canvas.rect,ctrans);
            
            var color:uint=Math.random()*0xFFFFFF;
            
            var sp:Sprite=new Sprite();
            
            var mat:Matrix=new Matrix();
            
            var queue:Vector.<Part>=new Vector.<Part>();
            var p:Part=new Part(mouseX,mouseY,Math.random()*50+50);
            queue.push(p);
            
            while(queue.length>0)
            {
                p=queue.shift();
                sp.graphics.clear()
                sp.graphics.lineStyle(1,color);
                sp.graphics.drawCircle(0,0,p.size);
                mat.identity();
                mat.translate(p.x,p.y);
                canvas.draw(sp,mat);
                
                var childnum:Number=Math.random()*4+2;
                var cnt:int=0;
                var rad:Number=Math.random()*Math.PI*2;
                while(cnt++<childnum)
                {
                    var size:Number=p.size*(Math.random()*0.4+0.2);
                    if(size>5)
                    {
                        rad+=Math.PI*2/childnum;
                        queue.push(new Part(
                            p.x+Math.cos(rad)*p.size,
                            p.y+Math.sin(rad)*p.size,
                            size));
                    }
                }
            }
            
            canvas.applyFilter(canvas,canvas.rect,canvas.rect.topLeft,bfilter);
            canvas.unlock();
        }
    }
}

class Part
{
    public function toString():String{return x+"/"+y+"/"+size;}
    public function Part(x:Number,y:Number,size:Number)
    {
        this.x=x;
        this.y=y;
        this.size=size;
    }
    public var x:Number;
    public var y:Number;
    public var size:Number;
}