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: 再帰関数

Get Adobe Flash player
by whirlpower 18 Oct 2009
package
{
	import flash.display.Sprite;
	
	public class TreeDraw extends Sprite
	{
		/**
		 * SpriteのRotationで枝をつなぐやりかたに改造してみた。
		 * 枝を作ると、lifeを消費しながら分裂を繰り返す。lifeが0になると、分裂を止める。
		 */
		public function TreeDraw():void
		{
			var plant:StickPlant = new StickPlant( 8 );
			plant.x = stage.stageWidth / 2;
			plant.y	= stage.stageHeight - 30;
			plant.rotation = -90;
			addChild( plant );
		}
	}
}

import flash.display.Sprite;

// 枝分かれする木の枝
internal class StickPlant extends Sprite
{		
	private var life	:int = 0;	// 寿命
	private var multiplication :int = 3;	// 増殖する回数
	private var color	:int = 0x00FF00;	// 色
	
	public function StickPlant( life:int ):void
	{
		this.life=life;
		var length:Number = ( life * Math.random() * 5 ) + 20;
		
		// 自身の色を決める
		var _color:int = color - ( life * 0x002200 );
		if ( _color < 0x004400 ) _color = 0x004400;
		
		// グラフィックを描画する
		graphics.lineStyle( life*0.5, _color );
		graphics.moveTo( 0, 0 );
		graphics.lineTo( length, 0 );
		
		// ライフを1使い小枝を生やす
		if ( life-- < 1 ) return;
		for ( var i:int = 0; i < multiplication; i++) 
		{
			var plant:StickPlant = new StickPlant( life );
			plant.x = length;
			plant.rotation = 35 * ( Math.random() - Math.random() );
			addChild( plant );
		}
	}
}