通过处理绘制分形树

Drawing a Fractal Tree by Processing

我想在加工中画一棵分形树,但我不知道怎么做。而我的想法是画一个二叉树。但是树必须有更多的分支。而且我不知道如何编码。请帮帮我,thanks.Now 我画了一个 2D 树,但是我的老板让我把它改成 3D.And 这是我的代码,我不知道如何制作 it.And 我我是 Processing 的新人 programing.Please 帮帮我。

void tree(float treeLength, float strokeWeight, int currentTreeStep)
{
    if (currentTreeStep < maxTreeSteps) {

        if(currentTreeStep >= 8 && currentTreeStep <=10)
            stroke(#558351); //set color light green
        else{
            if(currentTreeStep >10 && currentTreeStep <=20)
                stroke(#199B0E); //set hard green        
            else{
                stroke(#311919);//set branch color
            }
        }
        strokeCap(PROJECT);
        strokeWeight(strokeWeight);
        line(0, 0, 0, -treeLength);  
        translate(0, -treeLength);

        strokeWeight *= 0.5;
        treeLength *= 0.75;

        if (treeLength > 1) {
            pushMatrix();
            rotate(radians(branchAngle));
            tree(treeLength, strokeWeight, currentTreeStep + 1);
            popMatrix();

            pushMatrix();
            rotate(-radians(branchAngle));
            tree(treeLength, strokeWeight, currentTreeStep + 1);
            popMatrix();
        }  
    }
}

一般来说,从 2D(主要是三角函数)转移到 3D(线性代数:向量和矩阵乘法)并不像人们想象的那么直观。

看看这个 example 我上过的一门课程。

希望您也能看到 3D 矩阵乘法部分的实际应用