Dans la vidéo j’utilise monotonic
pour temporiser le jeu, dans la version ci-dessous j’ai simplifié en ne mettant que sleep
.
from kandinsky import fill_rect, get_pixel from ion import * from time import sleep BL = (248,255,248) NR = (0,)*3 GR = (220,)*3 d = 8 def grille(): for i in range(320//d): fill_rect(d*i,0,1,d*(220//d),GR) if d*i <= 220:fill_rect(0,d*i,320,1,GR) def dec(c,n): v = list(c) if n == 4: v = [max(0, e - 51) for e in v] elif n == 6: v = [min(255, e + 51) for e in v] else: v[n] = v[n] + 51 % 306 return tuple(v) def touche(x,y,e,coul): c = coul if e else get_pixel(x+1,y+1) etat = 0 while True: sleep(.08) dx,dy = keydown(KEY_RIGHT)-keydown(KEY_LEFT), keydown(KEY_DOWN)-keydown(KEY_UP) if keydown(KEY_ZERO): e = 0 if keydown(KEY_ONE): e,c = 1,(255,0,0) if keydown(KEY_TWO): e,c = 1,(0,255,0) if keydown(KEY_THREE): e,c = 1,(0,0,255) if keydown(KEY_FOUR): e,c = 1,dec(c,4) if keydown(KEY_SIX): e,c = 1,dec(c,6) if keydown(KEY_SEVEN): e,c = 1,dec(c,0) if keydown(KEY_EIGHT): e,c = 1,dec(c,1) if keydown(KEY_NINE): e,c = 1,dec(c,2) if keydown(KEY_FIVE): e,c = 1,BL if dx != 0 or dy != 0: rect(x,y,c) return [dx, dy, e, c] etat = 1 - etat if e:rect(x,y,c) else:rect(x,y,c if etat else GR) def rect(x,y,c): fill_rect(x+1,y+1,d-1,d-1,c) def pixelart(): grille() x,y,t = d*(160//d),d*(100//d),0 ecrire, coul = 0, NR while True: t = touche(x,y,ecrire,coul) x += d * t[0] y += d * t[1] ecrire = t[2] coul = t[3] pixelart()