plop
This commit is contained in:
parent
f99cd9fd4a
commit
db9f6b0cb8
2 changed files with 11 additions and 1 deletions
10
lsystem.py
10
lsystem.py
|
@ -44,6 +44,14 @@ class Tortue:
|
|||
""" Retourne au précédent état mémorisé. """
|
||||
self.pos, self.angle = self.stack.pop(-1)
|
||||
|
||||
def saut(self, r):
|
||||
x,y = self.pos
|
||||
self.pos = (
|
||||
x + r*np.cos(self.angle),
|
||||
y + r*np.sin(self.angle)
|
||||
)
|
||||
|
||||
|
||||
def trace(self, s, alpha):
|
||||
""" Trace la chaîne de caractères s. """
|
||||
plt.autoscale()
|
||||
|
@ -56,6 +64,8 @@ class Tortue:
|
|||
self.push()
|
||||
elif c == ']':
|
||||
self.pop()
|
||||
elif c.islower():
|
||||
self.saut(1)
|
||||
else:
|
||||
self.avance(1)
|
||||
|
||||
|
|
2
test.py
2
test.py
|
@ -18,7 +18,7 @@ plt.show()
|
|||
|
||||
plt.close('all')
|
||||
t = ls.Tortue(0)
|
||||
s = ls.genere({"A":"A-B+A+B-A", "B":"BB"},"A−B−B", 5)
|
||||
s = ls.genere({"A":"A-B+A+B-A", "B":"BB"},"A-B-B", 4)
|
||||
t.trace(s,2*np.pi/3)
|
||||
plt.show()
|
||||
|
||||
|
|
Loading…
Reference in a new issue