Lance de 1 à 9 dés et affiche les faces
from random import choice from kandinsky import set_pixel from ion import keydown,KEY_BACK,KEY_EXE,KEY_PLUS,KEY_MINUS,KEY_DOT,KEY_ONE,KEY_TWO,KEY_THREE,KEY_FOUR,KEY_FIVE,KEY_SIX,KEY_SEVEN,KEY_EIGHT,KEY_NINE from time import sleep nbdir=[KEY_ONE,KEY_TWO,KEY_THREE,KEY_FOUR,KEY_FIVE,KEY_SIX,KEY_SEVEN,KEY_EIGHT,KEY_NINE] num=((((1,1),),), (((0,0),(2,2)), ((0,2),(2,0))), (((0,2),(1,1),(2,0)), ((0,0),(1,1),(2,2))), (((0,0),(0,2),(2,0),(2,2)),), (((0,0),(0,2),(1,1),(2,0),(2,2)),), (((0,0),(0,1),(0,2),(2,0),(2,1),(2,2)), ((0,0),(0,2),(1,0),(1,2),(2,0),(2,2)))) taille=50 pos=(((160-taille//2,110-taille//2),), ((160-3*taille//2,110-taille//2), (160+taille//2,110-taille//2)), ((160+taille//2,110+taille//2), (160-3*taille//2,110+taille//2), (160-taille//2,110-3*taille//2)), ((160-3*taille//2,110+taille//2), (160+taille//2,110+taille//2), (160-3*taille//2,110-3*taille//2), (160+taille//2,110-3*taille//2)), ((160-3*taille//2,110-3*taille//2), (160+taille//2,110-3*taille//2), (160-5*taille//2,110+taille//2), (160-taille//2,110+taille//2), (160+3*taille//2,110+taille//2)), ((160-5*taille//2,110-3*taille//2), (160-taille//2,110-3*taille//2), (160+3*taille//2,110-3*taille//2), (160-5*taille//2,110+taille//2), (160-taille//2,110+taille//2), (160+3*taille//2,110+taille//2)), ((160-3*taille//2,110-2*taille), (160+taille//2,110-2*taille), (160-2*taille,110-taille//2), (160-taille//2,110-taille//2), (160+taille,110-taille//2), (160-3*taille//2,110+taille), (160+taille//2,110+taille)), ((160-3*taille//2,110-2*taille), (160+taille//2,110-2*taille), (160-2*taille,110-taille//2), (160-taille//2,110-taille//2), (160+taille,110-taille//2), (160-2*taille,110+taille), (160-taille//2,110+taille), (160+taille,110+taille)), ((160-2*taille,110-2*taille), (160-taille//2,110-2*taille), (160+taille,110-2*taille), (160-2*taille,110-taille//2), (160-taille//2,110-taille//2), (160+taille,110-taille//2), (160-2*taille,110+taille), (160-taille//2,110+taille), (160+taille,110+taille))) croix=[] point=taille//10 for i in range(-point,point+1): for j in range(-point,point+1): if i*i+j*j<point*point: croix.append((i,j)) def carre(x,y,c,p): for i in range(taille): set_pixel(x,y+i,c) set_pixel(x+i,y,c) set_pixel(x+taille,y+i,c) set_pixel(x+i,y+taille,c) for a,b in p: for X,Y in croix: set_pixel(taille//6+x+taille*a//3+X,taille//6+y+taille*b//3+Y,c) def la(): nb=0 carres=[(0,0,(255,255,255),((1,1),))] trie=False while True: trace=False if keydown(KEY_BACK): break elif keydown(KEY_DOT): trie=not trie trace=True elif keydown(KEY_EXE): trace=True elif keydown(KEY_PLUS): nb+=1 if nb>=8: nb=8 trace=True elif keydown(KEY_MINUS): nb-=1 if nb<=0: nb=0 trace=True else: for touche in nbdir: if keydown(touche): nb=nbdir.index(touche) trace=True break if trace: for x,y,_,p in carres: carre(x,y,(255,255,255),p) carres=[] for i in range(nb+1): p=choice(choice(num)) x,y=pos[nb][i] carres.append((x,y,(0,0,0),p)) if trie: carres.sort(key=lambda c:len(c[-1])) for x,y,c,p in carres: carre(x,y,c,p) sleep(.5)