import static util.SVGUtil.*;

public class Tree {
    /* 位置     縮小率    角度  */   
    private static double[][] branches1 = { { 1,      0.7,       11}    // 幹
                                           , { 0.45,   0.5,      -80}    // 左の枝
                                           , { 0.55,   0.45,      75} }; // 右の枝
    
    private static double[][] branches2 = { { 1,      0.7,      -11}    // 幹
                                          , { 0.45,   0.4,      -60}    // 左の枝
                                          , { 0.55,   0.45,      70} }; // 右の枝
        
    public static void generate(int d, double x, double y, double len, double angle, double color0, double[][] brs) {
        double x1, y1;

        if (d<=0) return;
        int color = hsb360(color0, 100, 100);     /* 色 */
        stroke(color);
        x1 = x + len * cos360(angle);
        y1 = y + len * sin360(angle);
        line(x, y, x1, y1);
            
        for (double[] branch : brs) {
            double r = branch[0];
            generate(d-1, x * (1 - r) + x1 * r, 
                     y * (1 - r) + y1 * r, 
                     len * branch[1], angle + branch[2], color0+8, brs);
        }
    }

    public static void main(String[] args) {
        start();
        rulers();
            
        strokeWeight(0.5);
        noFill();
            
        generate(7 /* 再帰の深さ */, centerX()-80, pageHeight()*0.8, pageHeight()/5.0, -60, 0, branches1);
        generate(7 /* 再帰の深さ */, centerX()+40, pageHeight()*0.8, pageHeight()/5.0, -60, 120, branches2);        
        finish();
        return;
    }
}
