diff --git a/examen.py b/examen.py index 9e805e1ac9d7cc8b2262506c6eb73014a7f528f4..a8311fa7bcefefd78446a1552a366fe192623f77 100644 --- a/examen.py +++ b/examen.py @@ -1,5 +1,6 @@ #Imports éventuels from itertools import chain +import matplotlib.pyplot as plt #Déclaration des classes et des fonctions class TabletteChocolat: @@ -55,11 +56,30 @@ class TabletteChocolat: return TabletteChocolat(self.m - i, self.n - j) else: raise ValueError('Coup impossible') + def plot(self): + m=self.m + n=self.n + plt.fill([0,m,m,0,0],[0,0,n,n,0], color='#D5B799') + for i in range(m): + for j in range(n): + X = [i+0.1, i+0.1, i+0.9, i+0.9, i+0.1] + Y = [j+0.1, j+0.9, j+0.9, j+0.1, j+0.1] + plt.plot(X,Y, color='#000') + n = 0 + m -=1 + plt.fill([m+0.1, m+0.1, m+0.9, m+0.9, m+0.1], [n+0.1, n+0.9, n+0.9, n+0.1, n+0.1], color='#000') + plt.gca().set_aspect('equal') + plt.axis('off') + plt.show() + plt.close() + + #Programme Principal -Tablette = TabletteChocolat(3,4) +Tablette = TabletteChocolat(4,3) print(Tablette) g= Tablette.coups_possibles() print(list(g)) print(Tablette.est_possible(1,0)) -biscuit = Tablette.coupe(1,0) \ No newline at end of file +biscuit = Tablette.coupe(1,0) +Tablette.plot() \ No newline at end of file