def force_cut(lstring): fake_rule = """ Fake: produce Fake""" fake_lsys = Lsystem() fake_lsys.addRule(fake_rule) fake_lsys.axiom = lstring return fake_lsys.iterate()
def lsystem(file_name, axiom='', derivationlength=-1, parameters={}): """ Build a lsystem object from file_name """ l = Lsystem(file_name, parameters) if len(axiom): l.makeCurrent() if type(axiom) != AxialTree: axiom = AxialTree(axiom) l.axiom = axiom #l.done() if derivationlength >= 0: l.derivationLength = derivationlength return l
def lsystem(file_name, axiom = '', derivationlength = -1, parameters = {}): """ Build a lsystem object from file_name """ l = Lsystem(file_name, parameters) if len(axiom): l.makeCurrent() if type(axiom) != AxialTree: axiom = AxialTree(axiom) l.axiom = axiom #l.done() if derivationlength >= 0: l.derivationLength = derivationlength return l
N = 2 derivation length: N production: F(x) : produce F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0) endlsystem ''' lsystem.setCode(str(code), context) lsystem.axiom = "_(0.01)-(90)F(1)" print('\n----lsystem:') print(lsystem) print('\n----axialtree:', axialtree) axialtree = lsystem.iterate(3) print('\n----lsystem:') print(lsystem) print('\n----axialtree:', axialtree) lsystem.getLastIterationNb() # iterate 4 -> getLastIterationNb == 3 lsystem.derivationLength # see keyword in lpy code scene = lsystem.sceneInterpretation(axialtree)
N = 2 derivation length: N production: F(x) : produce F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0) endlsystem ''' lsystem.setCode(str(code), context) lsystem.axiom = "_(0.01)-(90)F(1)" print('\n----lsystem:') print(lsystem) print('\n----axialtree:', axialtree) axialtree = lsystem.iterate(3) print('\n----lsystem:') print(lsystem) print('\n----axialtree:', axialtree) lsystem.getLastIterationNb() # iterate 4 -> getLastIterationNb == 3 lsystem.derivationLength # see keyword in lpy code
def shoot_grow(g, demand_only=True): lsys = Lsystem(str(os.path.join(lsysdir, 'morphogenesis.lpy')), {'demand_only': demand_only}) lsys.axiom = mtg2lpy(g, lsys, AxialTree()) axt = lsys.iterate() scene = lsys.sceneInterpretation(axt) return lpy2mtg(axt, lsys, scene)