Bonjour tous le monde,

je travaille sur le fourmi de Langton. Pour cela je dois utiliser les notions de classe et tkinter. J'ai programmé mais je bloque sur la fonction after.Pour créer une animation, je dois utiliser la fonction after qui est intégré sur tkinter. Mais lorsque j'invoque, il m demande de fournir direction, position et tableau. Alors que je lui fourni dans le main.

Pouvez-vous me dire où se trouve ma faute?

Merci tous

tuba uba

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
f
from  tkinter import *
import random
 
class fourmie(object):
 
    def __init__(self,longeur,largeur, cellule):
        self.longeur = longeur
        self.largeur = largeur
        self.cellule = cellule
        self.tableur2 = []
        self.root = Tk()
        self.cnv = Canvas(self.root, width = 100, height = 100,background = "yellow")
 
    def creation_tableau(self):
        for i in range(self.largeur):
            self.tableur2.append([])
            for j in range(self.longeur):
                self.tableur2[i].append(0)
        return self.tableur2
 
    def place_de_formie(self): # place aléatoire de la fourmie 
        a = random.randint(2,100)
        b = random.randint(2,100)
        return a,b
 
    def matrice_1(self):
        print(self.tableur2)
 
    def dessiner_carre(self,cordonne_x, cordonne_y):
      x,y = cordonne_y*self.cellule, cordonne_x*self.cellule
      carre =self.cnv.create_rectangle((x,y),(x+self.cellule, y+self.cellule), fill = "red" , outline ='')
      return carre
 
 
    def ar(self, position_fourmie, direction_fourmie, tableau): # fonction qui permet de connaitre les information sur le fourmie 
        i,j = position_fourmie
 
        if tableau[i][j] == 0:
            if direction_fourmie == "N":
                r = (i,j+1),"E"
            elif direction_forumie == "S":
                r = (i,j-1), "W"
            elif direction_fourmie == "E":
                r = (i+1, j), "S"
            elif direction_fourmie == "W":
                r = (i-1,j),"N"
        else :
            if direction_forumie == "S":
                r = (i,j+1),"E"
            elif direction_fourmie == "N":
                r = (i,j-1), "W"
            elif direction_fourmie == "W":
                r = (i+1,j), "S"
            elif direction_forumie == "E":
                r = (i-1,j),"N"
        return r
 
 
 
    def dessine_tableau(self, position_fourmie, direction_fourmie, tableau):
        (i_indice, j_indice),direction = self.ar(position_fourmie, direction_fourmie, tableau)
        i,j = position_fourmie
 
        print(i)
        print(j)
        carre = tableau[i][j]
        if carre == 0:
            carre = self.dessiner_carre(i,j)
            tableau[i][j] = carre
        else :
            cnv.delete(carre)
            tableau[i][j] = 0
 
        return (i_indice,j_indice), direction        
 
 
 
    def deplacement(self, position_fourmie, direction_fourmie, tableau):
        i,j = position_fourmie
 
        if tableau[i][j] == 0:
            if direction_fourmie == "N":
                r = (i,j+1),"E"
            elif direction_forumie == "S":
                r = (i,j-1), "W"
            elif direction_fourmie == "E":
                r = (i+1, j), "S"
            elif direction_fourmie == "W":
                r = (i-1,j),"N"
        else :
            if direction_forumie == "S":
                r = (i,j+1),"E"
            elif direction_fourmie == "N":
                r = (i,j-1), "W"
            elif direction_fourmie == "W":
                r = (i+1,j), "S"
            elif direction_forumie == "E":
                r = (i-1,j),"N"
        return r
 
 
    def animation(self, position, direction,tableau):
        self.position,self.direction = self.ar(position,direction, tableau)
        self.root.after(1, self.animation)
        self.root.mainloop()
 
 
if __name__=='__main__':
    valeur = fourmie(100,100,1)
    valeur.animation((12,15), "N", valeur.creation_tableau())
erreur :
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 1892, in __call__
return self.func(*args)
File "/usr/lib/python3.8/tkinter/__init__.py", line 814, in callit
func(*args)
TypeError: animation() missing 3 required positional arguments: 'position', 'direction', and 'tableau'