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

フラクタルな樹

再帰を使ってフラクタルな樹を描く実験
Get Adobe Flash player
by gam-22 07 Mar 2011
/**
 * Copyright gam-22 ( http://wonderfl.net/user/gam-22 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3esi
 */

// 参考ページ
// http://gihyo.jp/design/feature/01/frocessing/0002?page=4

package {
    import flash.display.AVM1Movie;
    import frocessing.display.F5MovieClip2D;
    
    [SWF(width=465,height=465,backgroundColor=0xFFFFFF)]
    public class tree extends F5MovieClip2D
    {
        private var leaf_length:Number = 200;// 葉っぱの長さ
        private var leaf_max:int = 20;//        葉っぱの数
        private var recursive_max:int = 4;//    再帰回数
        
        public function setup():void {
        // コンストラクタ
            
            translate( 465/2, 465 );
            
            //線と塗りの色指定
            stroke( 0,122,0,  0.5 );
            noFill();
            
            // 軸を描画
            line (0,0,0,-leaf_length*2);
      
            draw_leaves(recursive_max);

        }
        
        private function draw_leaves( n:int ):void {
            
            if ( n-- <= 0 ) return;
            
            for (var i:int = 0; i < leaf_max; i++) {
                scale(0.8);
                translate( 0, -leaf_length/2 );
                pushMatrix();
                if (i%2) {
                    rotate( Math.PI/6 );
                } else {
                    rotate( -Math.PI/6 );
                }
                
                line (0,0,0,-leaf_length);
                
                scale(0.5);
                
                draw_leaves(n);

                popMatrix();
            }
        }

    }
}