我想在處理中繪製分形樹,但我不知道如何製作它。我的想法是繪製一棵二叉樹。但樹必須有更多的分支。我不知道如何編碼。請幫助我,謝謝。現在我畫了一棵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](http://stackoverflow.com/help/mcve)在哪裏?請注意,Processing編輯器附帶了大量的例子,其中包括幾個關於分形樹的例子。 –
感謝您的幫助,我通過Google修復了二維樹。但是如何將其更改爲3D還有一個問題。 – WangYao