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 いろいろ修正
 2009/06/28 間違いをみつけた
Get Adobe Flash player
by hacker_sd5jw8qk 29 Jul 2009
// forked from osamX's FractalTree
// 2009/01/07 初AS3です。
// 2009/01/10 いろいろ修正
// 2009/06/28 間違いをみつけた

package 
{
	import flash.display.Sprite;

	public class FractalTree extends Sprite
	{
		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;

		public function FractalTree():void {
			DrawBranch(MaxDepth, -Math.PI / 2, 85, 235, 380);
		}

		private function DrawBranch(
			Depth:uint,
			MyRadian:Number,
			Length:Number,
			OffsetX:Number,
			OffsetY:Number
			):void
		{
			if (Depth < 2) return;

			var MyVectorX:Number = 1 * Length * Math.cos(MyRadian);
			var MyVectorY:Number = 0.8 * Length * Math.sin(MyRadian);
			
			this.graphics.moveTo(OffsetX, OffsetY);
			var Color:uint = 0xFFFFFF*Math.random();
			this.graphics.lineStyle(Depth, Color);
			this.graphics.lineTo(MyVectorX + OffsetX, MyVectorY + OffsetY);

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