ASD-1/test.py
2017-12-05 23:23:31 +01:00

56 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import matplotlib.pyplot as plt
import lsystem as ls
L1 = ls.genere({"A": "AB+A+BA", "B": "BB"}, "ABB", 1)
print("L1 = " + L1)
assert(L1 == "AB+A+BABBBB")
L2 = ls.genere({"A": "AB+A+BA", "B": "BB"}, "ABB", 2)
assert(L2 == "AB+A+BABB+AB+A+BA+BBAB+A+BABBBBBBBB")
plt.close('all')
t = ls.Tortue(0)
for i in range(4):
t.avance(20)
t.tourne(np.pi/2)
plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"A-B+A+B-A", "B":"BB"},"A-B-B", 4)
t.trace(s,2*np.pi/3)
plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"A-A++A-A", "B":"BB"},"A++A++A", 4)
t.trace(s,np.pi/3)
plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"A[+A]A[-A]A"},"A", 3)
t.trace(s,22*np.pi/180)
plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"B[+A][-A]BA", "B":"BB"},"A", 4)
t.trace(s,25*np.pi/180)
plt.show()
plt.close('all')
t = ls.Tortue(0)
s = ls.genere({"A":"A+b-AA+A+AA+Ab+AA-B+AA-A-AA-Ab-AAA", "b":"bbb"},"A", 2)
t.trace(s,np.pi/2)
plt.show()
plt.close('all')
for i in range(5):
t = ls.Tortue(0, i)
s = ls.genere3({"A":[(2,"A[+A]A[-A]A"), (1,"A[+A]A"), (1,"A[-A]A")]},"A", 5)
t.trace(s,np.pi/6)
plt.show()