【发布时间】:2015-06-04 06:07:35
【问题描述】:
我想在处理中绘制分形树,但我不知道如何制作。我的想法是画一棵二叉树。但是这棵树必须有更多的树枝。而且我不知道如何编码。请帮帮我,谢谢。现在我画了一个 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();
}
}
}
【问题讨论】:
-
其中哪一部分给您带来了麻烦?你的MCVE 在哪里?请注意,Processing 编辑器附带了大量示例,其中包括几个关于分形树的示例。
-
感谢您的帮助,我已经通过 Google 修复了 2D 树。但是如何将其更改为 3D 存在问题。
标签: java image-processing recursion processing fractals