This commit is contained in:
Klafyvel 2017-12-05 23:23:31 +01:00
parent f99cd9fd4a
commit db9f6b0cb8
2 changed files with 11 additions and 1 deletions

View file

@ -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)

View file

@ -18,7 +18,7 @@ plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"A-B+A+B-A", "B":"BB"},"ABB", 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()