我想在处理中绘制一个分形树,但我不知道如何制作它。我的想法是画一棵二叉树。但树必须有更多的分支。而且我不知道如何编码。请帮助我,谢谢。现在我画了一张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();
}
}
}
答案 0 :(得分:0)