通过处理绘制分形树

时间:2015-06-04 06:07:36

标签: java image-processing recursion processing fractals

我想在处理中绘制一个分形树,但我不知道如何制作它。我的想法是画一棵二叉树。但树必须有更多的分支。而且我不知道如何编码。请帮助我,谢谢。现在我画了一张2D树,但我的老板让我把它改成3D。这是我的代码,我不知道怎么做。我和我处理编程的新人。请帮帮我。

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();
        }  
    }
}

1 个答案:

答案 0 :(得分:0)

一般来说,它并不像人们可能从2D(大多数是三角)到3D(线性代数:向量和矩阵乘法)那样直观。

从我做过的其中一门课程中查看此example

enter image description here

希望你也会看到3D矩阵乘法部分的运作

相关问题