rewriting – 書き換え関数

L-systemを実現する重要な関数です。

def rewrite(o,r,t):
    result = o.replace(r,t)
    return result

使用例

s = "F"
s = rewrite(s,'F','F+F-F-F+F') 
print s 
s = rewrite(s,'F','F+F-F-F+F') 
print s 
s = rewrite(s,'F','F+F-F-F+F') 
print s 

F+F-F-F+F

F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F

F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F

Comments are closed.