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: FractalTree

2009/01/07 初AS3です。
2009/01/10 いろいろ修正
-----------
クリックの度に新しい形の木を作成。
-----------
Get Adobe Flash player
by s26 22 Dec 2012
// forked from osamX's FractalTree
// 2009/01/07 初AS3です。
// 2009/01/10 いろいろ修正


/*-----------
クリックの度に新しい形の木を作成。
-----------*/
package 
{
    import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
    public class FractalTree extends Sprite
    {
        public function FractalTree():void
        {
            DrawBranch(true, MaxDepth, -Math.PI / 2, 85, 235, 380);
                        stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseLDownFunc);
        }
        private const Radian:Number =20;
        private const Radian1:Number = Math.PI * Radian / 180;
        private const Radian2:Number = -Math.PI * Radian / 180;
        private const MaxDepth:Number = 10;
        private function MouseLDownFunc(evt:Event):void{
    graphics.clear();
    graphics.beginFill(0x000000)
   graphics.drawRect(0,0,498,498);
    graphics.endFill();
    DrawBranch(true, MaxDepth, -Math.PI / 2, 85, 235, 380);
    }
        private function DrawBranch(
            Direction:Boolean,
            Depth:uint,
            MyRadian:Number,
            Length:Number,
            OffsetX:Number,
            OffsetY:Number
            ):void
        {
            
            var MyVectorX:Number = 0.8 * Length * Math.cos(MyRadian+1.8*Math.random()-0.9);
            var MyVectorY:Number = 0.8 * Length * Math.sin(MyRadian+1.8*Math.random()-0.9);
            
            
            this.graphics.moveTo(OffsetX, OffsetY);
            
            var Color:uint = 0xffffff
            this.graphics.lineStyle(Depth, Color ,1.0 ,false,"none","round","round");
            this.graphics.lineTo(MyVectorX + OffsetX, MyVectorY + OffsetY);
            
            if (Depth < 2) return;

            DrawBranch(
                true,
                Depth - 1,
                MyRadian + Radian1,
                Length*0.8,
                MyVectorX + OffsetX,
                MyVectorY + OffsetY
            );

            DrawBranch(
                false,
                Depth - 1,
                MyRadian + Radian2,
                Length*0.8,
                MyVectorX + OffsetX,
                MyVectorY + OffsetY
            );
            
        }
    }
}