再帰関数でフラクタル

by cpu_t
再帰関数っていうものを使ってみたかった。
基本的な考えは合ってるはず
♥0 | Line 27 | Modified 2010-02-14 12:41:47 | MIT License
play

ActionScript3 source code

/**
 * 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/lsIT
 */

// 再帰関数っていうものを使ってみたかった。
// 基本的な考えは合ってるはず
package {
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	[SWF(width = 465, height = 465, backgroundColor = 0xFFFFFF, frameRate = 60)]
    public class FlashTest extends Sprite {
        public function FlashTest() {
			addEventListener(Event.ADDED_TO_STAGE, init);
        }
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			drawLine(stage.stageWidth * .2, stage.stageHeight * .5, 15, 0);
		}
		private function drawLine(x:Number, y:Number, n:Number, a:Number):void
		{
			if (n < 0) return;
			this.graphics.lineStyle( -1, 0x000000);
			this.graphics.moveTo(x, y);
			x += Math.cos(a) * n * 3;
			y += Math.sin(a) * n * 3;
			this.graphics.lineTo(x, y);
			drawLine(x, y,--n, a + (20) / 180 * Math.PI);
			drawLine(x, y,--n, a + (-80) / 180 * Math.PI);
		}
    }
}

Forked