usr bin python encoding utf-8 __version__ class LSystem object def __i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# -*- encoding: utf-8 -*-
__version__=0.2
class LSystem(object):
def __init__(self,funcs,deep=3):
self.x=0
self.y=0
self.leftB=0
self.rightB=0
self.topB=0
self.bottomB=0
self.rules = dict()
self.deep = deep
self.funcs=funcs
print self.funcs
def setAxiom(self,axiom):
self.axiom = axiom
def registerRule(self,name,rule):
# if not name in self.funcs:
self.rules[name]=rule
def setDeep(self,deep):
self.deep = deep
def interSteps(self,string,deep):
for c in string:
if self.rules.has_key(c):
if deep<self.deep:
for ch in self.interSteps(self.rules[c],deep+1):
yield ch
elif c in self.funcs:
yield c
else:
yield c
def steps(self):
yield self.interSteps(self.axiom,1)
# vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: