package sample.svg.contributed;
import static util.SVGUtil.*;

public class Chen {

    public static final int X=150;
    public static final int Y=300;
    public static final int W=210;
    public static final int H=200;
        
    static void branch(double h){
        //枝ごと前より2/3ラジアンの長さになる
        h *=0.66;
                        
        double theta;
                        
        //Xで0~90のアングルを設定する
        double a = (X/(double) Y)*90d;
        //ラジアンに変更する
        theta = radians(a);
                        
        //枝の長さが2ピクセルかそれ以下に再帰を終了させる
        if (h > 2) {
            pushMatrix();//現在の位置をセーブする
            rotate(theta);//thetaで回転させる
            line(0, 0, 0, -h);//枝を描く
            translate(0, -h);//枝の端に移動
            branch(h);//再帰で新たな枝を描く
            popMatrix();//セーブしたマトリクスをポップする
                                
            //同じことを繰り返し、左側の枝を描く
            pushMatrix();
            rotate(-theta);
            line(0, 0, 0, -h);
            translate(0, -h);
            branch(h);
            popMatrix();
        }
    }

    public static void main(String[] args) {
        start();
                
        fill(0x87cefa);
        upperBar(3);
        fill(0x00ff00);
        lowerBar(3);
                
        fill(0x008b8b);
        textFont("Verdana", 12);
        fill(0x00bfff);
        text("@Kagawa Univ.", 130, 170);
                                
        stroke(0xffa500);
        strokeWeight(1);
        //下からツリーを書き始める
        translate(W/2,H);
        //ツリーの幹を描く
        line(45,0,45,-35);
        //線の端に移動する
        translate(45,-35);
        //再帰で枝を描く
        branch(95);     
                
        finish();
        return ;
    }
}
