serpent carré sur chemin carré
from kandinsky import * import time # taille et espacement des carrés # donnant décallage carré tailleC = 20 spcC = 5 decC = tailleC + spcC x = 50 y = 40 L1 = [[x, y], [x + decC, y], [x + 2*decC, y]] L2 = [[x, y+ decC], [x + decC, y+ decC], [x + 2*decC, y+ decC]] L3 = [[x, y+ 2*decC], [x + decC, y+ 2*decC], [x + 2*decC, y+ 2*decC]] grille = [L1, L2, L3] circuit = [[0,0],[1,0],[2,0],[2,1],[2,2],[1,2],[0,2],[0,1]] def traceCarre(iCircuit, grille): # Actif en noir xG, yG = circuit[iCircuit] fill_rect(x+xG*decC, y+yG*decC, tailleC, tailleC, color(0,0,0)) # ancien actif passe en gris if iCircuit > 0: iCircuit = iCircuit - 1 else: iCircuit = len(iCircuit) xG, yG = circuit[iCircuit] fill_rect(x+xG*decC, y+yG*decC, tailleC, tailleC, color(100,100,100)) # ancien gris devient gris clair if iCircuit > 0: iCircuit = iCircuit - 1 else: iCircuit = len(iCircuit) xG, yG = circuit[iCircuit] fill_rect(x+xG*decC, y+yG*decC, tailleC, tailleC, color(200,200,200)) # ancien gris clair devient blanc if iCircuit > 0: iCircuit = iCircuit - 1 else: iCircuit = len(iCircuit) xG, yG = circuit[iCircuit] fill_rect(x+xG*decC, y+yG*decC, tailleC, tailleC, color(255,255,255)) tps = 20 iDebCircuit = 0 while tps > 0: traceCarre(iDebCircuit, grille) iDebCircuit = (iDebCircuit + 1)%len(circuit) tps = tps - 1 time.sleep(0.001) traceCarre(4, grille)