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: forked from: Fractal Tree

[SWF(width="400", height="400", backgroundColor="#d1d1d1")]
/**
 * Copyright e_2o ( http://wonderfl.net/user/e_2o )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9OKO
 */

// forked from takuya1021's forked from: Fractal Tree
// forked from RobotCaleb's Fractal Tree
package
{
    import flash.display.Sprite;
    import flash.display.StageScaleMode;

  //  [SWF(width="400", height="400", backgroundColor="#d1d1d1")]
    public class Fractal extends Sprite
    {
                 private const MAXSTEPS:Number = 5;
                private const angleLeft:Number = Math.PI/180*20;
                private const angleRight:Number = Math.PI/180*20;
                private const lengthMult:Number = 0.75;
                
        public function Fractal()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            DrawFractal();
        }
    
        public function DrawFractal():void
        {
                        var angle:Number = Math.PI / 180 *270;
            DrawPiece(angle, 200, 10, 100, 0);
        }
        
        public function DrawPiece(angle:Number, x:Number, y:Number, length:Number, count:Number):void
        {
            if (count < MAXSTEPS)
            {
                var newLength:Number = length * lengthMult;
                var newX:Number = x - Math.cos(angle) * length;
                var newY:Number = y - Math.sin(angle) * length;
                
                    graphics.lineStyle(0, 0xff000000);
                graphics.moveTo(x, y);
                graphics.lineTo(newX, newY);
                graphics.beginFill(0xffff);
                graphics.drawRect(x-5,y-5,10,10);
                
                DrawPiece(angle + angleRight, newX, newY, newLength, count + 1);
                DrawPiece(angle - angleLeft, newX, newY, newLength, count + 1);
            }
        }
    }
}