Utilisation de classes pour animer 9 carrés
Visuel final sur TikTok Ma chaine YouTubefrom random import randint from kandinsky import * from time import sleep fill_rect(0,0,320,222,(0,0,0)) pos = 0,1,2,7,8,3,6,5,4, class carre(): def __init__(self,i): self.x = i % 3 self.y = i // 3 self.anim = 484, 510, 26, 27, 1, 17, 9, 2, 16, 17, 26, 510 self.frames = len(self.anim) self.t = pos[i] self.rot = (0,1,2,3,4,5,6,7,8),(6,3,0,7,4,1,8,5,2),(2,5,8,1,4,7,0,3,6),(8,7,6,5,4,3,2,1,0) def affiche(self): self.t = (self.t + 1) % self.frames cases = ("0" * 8 + bin(self.anim[self.t])[2:])[-9:] v = (randint(180,255), randint(180,255), randint(180,255),) for i in range(9): for j in range(4): coul = v if cases[self.rot[j][i]] == "1" else (0,) * 3 c, l = i % 3, i // 3 fill_rect(80 + 54 * self.x + 24 * (j % 2) + 8 * c, 30 + 54 * self.y + 24 * (j // 2) + 8 * l, 8, 8, coul) visuel = [] for i in range(9): visuel.append(carre(i)) while True: for c in visuel: c.affiche() sleep(.1)