Hello I'm looking for a way to implement a simple L-system into function in python which would take three arguments : axiom , rules and number of interations(if iterations = 0 output would be previously input axiom). I came up with some code it only works on 1 iteration and I dont know how to implement more.
The code I came up with :
# x = axiom
# y = rules
# z would be iterations which I dont know how to implement
def lsystem(x,y):
output = ''
for i in x:
if i in y:
output += y[i]
else:
output += i
print(output)
rules = { "A" : "ABA" , "B" : "BBB"}
# output lsystem("AB",rules) ---> ABABBB
You need to return the given
axioms
ifiterations == 0
. In this function, you return the argumentaxioms
you've been given, so that ifiterations == 0
, you will return the given, untouched axioms.Then, later on, at the end of your
iteration
, ifiteration
there is, the newly created axioms you get from theiteration
is transfered intoaxioms
so that you will return the good value, and if need be, the nextiteration
will have the newly created axioms to iterate on. :)