forked from: 再帰関数でフラクタル

by ohisama forked from 再帰関数でフラクタル (diff: 9)
再帰関数っていうものを使ってみたかった。
基本的な考えは合ってるはず
♥0 | Line 30 | Modified 2013-02-03 22:11:35 | MIT License
play

ActionScript3 source code

/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/gJvC
 */

// forked from cpu_t's 再帰関数でフラクタル
// 再帰関数っていうものを使ってみたかった。
// 基本的な考えは合ってるはず
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, 0xff0000);
            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);
        }
    }
}