Petit jeu dont le but est de retrouver une couleur donnée en déplaçant 3 curseurs qui règlent les composantes Rouge, Verte et Bleue.
Une version simple (sans la partie jouable) est disponible ici.
from kandinsky import * from ion import * from time import sleep,monotonic from random import randint diff = 2 draw_string("Choix de la difficulté :",40,30,'orange') draw_string("Elevée",130,60,'blue') draw_string("Moyenne",125,85,'blue') draw_string("Faible",130,110,'blue') while keydown(KEY_EXE) or keydown(KEY_OK):True while not (keydown(KEY_EXE) or keydown(KEY_OK)): draw_string("[",100+5*(diff%2),35+25*diff,'blue') draw_string("]",110+10*10-5*(diff%2),35+25*diff,'blue') if keydown(KEY_DOWN) or keydown(KEY_UP): draw_string(" ",100+5*(diff%2),35+25*diff) draw_string(" ",110+10*10-5*(diff%2),35+25*diff) diff = (diff+keydown(KEY_DOWN)-keydown(KEY_UP)-1)%3+1 while keydown(KEY_DOWN) or keydown(KEY_UP):True x = 50 y = 50 r0 = g0 = b0 = 255 while 1: draw_string("Nouvelle partie",320//2+5,140,["white","black"][r0+g0+b0>384],(r0,g0,b0)) draw_string("appuyer sur EXE",320//2+5,160,["white","black"][r0+g0+b0>384],(r0,g0,b0)) while not (keydown(KEY_EXE) or keydown(KEY_OK)):True r = g = b = 145 r0=8*diff*randint(0,255//(8*diff)) g0=4*diff*randint(0,255//(4*diff)) b0=8*diff*randint(0,255//(8*diff)) fill_rect(320//2,0,320//2,222,(r0,g0,b0)) draw_string("Retrouve la",320//2+25,30,["white","black"][r0+g0+b0>384],(r0,g0,b0)) draw_string("couleur ! ",320//2+35,50,["white","black"][r0+g0+b0>384],(r0,g0,b0)) fini = False t = monotonic() r1 = g1 = b1 = 144 pos = 0 chgt = True for i in range(3): draw_string(str([r1,g1,b1][i]),x+15,y+18*i,"white",["red","green","blue"][i]) while not fini: if chgt or (r1,g1,b1) != (r,g,b): chgt = False for i in range(3): draw_string("< ",x-5,y+18*i,[(r1,g1,b1),["white","black"][r1+g1+b1>384]][pos == i],(r1,g1,b1)) draw_string(" >",x+45,y+18*i,[(r1,g1,b1),["white","black"][r1+g1+b1>384]][pos == i],(r1,g1,b1)) if (r1,g1,b1) != (r,g,b): r,g,b=r1,g1,b1 draw_string(" ",x+15,y+18*pos,"white",["red","green","blue"][pos]) draw_string(str([r,g,b][pos]),x+15+5*(3-len(str([r,g,b][pos]))),y+18*pos,"white",["red","green","blue"][pos]) fill_rect(0,0,320//2,50,(r,g,b)) fill_rect(0,50,x-5,110,(r,g,b)) fill_rect(x+65,50,320//2-(x+65),110,(r,g,b)) fill_rect(x-5,y+54,70,y+85-104,(r,g,b)) fill_rect(x-5,y+103,70,7,(r,g,b)) fill_rect(0,y+110,x-5-5*len(str(r)+str(g)+str(b)),222-(y+110),(r,g,b)) fill_rect(x+65+5*len(str(r)+str(g)+str(b)),y+110,320//2-(x+65)-5*len(str(r)+str(g)+str(b)),222-(y+110),(r,g,b)) fill_rect(x-5-5*len(str(r)+str(g)+str(b)),y+128,70+10*len(str(r)+str(g)+str(b)),222-(y+128),(r,g,b)) draw_string("#"+"0"*(2-len(hex(r)[2:]))+hex(r)[2:]+"0"*(2-len(hex(g)[2:]))+hex(g)[2:]+"0"*(2-len(hex(b)[2:]))+hex(b)[2:],x-5,y+85) draw_string("rgb("+str(r)+","+str(g)+","+str(b)+")",x-5-5*len(str(r)+str(g)+str(b)),y+110) if pos==0: r1 = (r+8*diff*(keydown(KEY_RIGHT)-keydown(KEY_LEFT)))%(256+8*(diff==3)) elif pos==1: g1 = (g+4*diff*(keydown(KEY_RIGHT)-keydown(KEY_LEFT)))%(256+8*(diff==3)) else: b1 = (b+8*diff*(keydown(KEY_RIGHT)-keydown(KEY_LEFT)))%(256+8*(diff==3)) if keydown(KEY_UP) or keydown(KEY_DOWN): pos = (pos-keydown(KEY_UP)+keydown(KEY_DOWN))%3 chgt = True sleep(0.05) sleep(0.1) if (r,g,b) == (r0,g0,b0): draw_string("Gagné en",320//2+40,80,["white","black"][r0+g0+b0>384],(r0,g0,b0)) draw_string(str(int(monotonic()-t))+" sec ! ",320//2+40,100,["white","black"][r0+g0+b0>384],(r0,g0,b0)) fini = True