![]() |
3D L-System 俯視圖,並用黑白光譜表現與生長原點的距離關係 |
L-System是一個透過既定的「規則 (rule)」做語意轉換的系統,並且可以將這份語意轉換成視覺上或寄何,是rule-based system,「規則」基本上是一個set,也就是看見A就替換成B,A與B各代表某一組特定的字元(vocabulary)。
L-Sytem中另一個用語是「axiom」,它代表變換「規則」中需要做轉換的特定字元,程式會在迭代過程中檢視「axiom」並替換新的文句,例如 :
Axiom : "F"
Rule : "F" >>>> " FF!!+[-F!!-F-!!F]-[-F+F!!+F!!] "
然後,我可以進一步設定這些字元在Rhino環境中所代表的動作(或是延伸到其它的環境也可以),比如說 :
for(int i = 0; i < rule.Length; i++){
string motion = rule[i].ToString();
if(string.Equals(motion, "F")) t.moveForward(); // 向前移動if(string.Equals(motion, "+")) t.turnRight(); // 右轉if(string.Equals(motion, "-")) t.turnLeft(); // 左轉if(string.Equals(motion, "!")) t.whiteSpace(); // 空格if(string.Equals(motion, "[")) t.storeLocation(); // 儲存當下位置if(string.Equals(motion, "]")) t.retriveLocation(); // 重設為上次儲存位置
}
留言
張貼留言
please leave a message