color_picker.py

Created by stimorol

Created on July 03, 2023

2.27 KB

Programme permettant de créer de nouvelles couleurs a partir d’autres couleurs préexistantes. Pour modifier le couleur, servez vous des 9 petites touches de la droite de la calculatrice : pour augmenter la saturation de rouge, vert ou bleu, utilisez respectivement la touche var, boite a outils, backspace (la touche supprimer). Pour diminuer la concentration de rouge, vert et bleu, utilisez respectivement les touches pi, racine carrée et au carré. Enfin, utilisez les touches i, virgule et exposant pour réinitialiser la teinte de rouge, vert et bleu. Une fois la couleur crée, appuyez sur OK pour que le programme vous renvoie la couleur !


from time import *
from kandinsky import *
from ion import *

blue=(0,0,255)
yellow=(248,252,0)
brown=(136,112,80)
gray=(160,164,160)
road=(255,200,100)
wood=(180,110,60)
sand=(250,230,40)
mount=(240,240,240)
Upsilon=(123,162,205)
NW=(255,183,52)
Omega=(193,50,46)

def show_col(col):
  fill_rect(0,0,214,222,tuple(col))
  draw_string(str(tuple(col)),5,200,"white",tuple(col))
  
def pick_color(newColor="white",defaults=['Upsilon','Omega','NW']):
  for i in range(len(defaults)):
    fill_rect(214,0+i*int(222/len(defaults)),107,int(222/len(defaults)),eval(defaults[i]))
    draw_string(str(defaults[i])+"\n"+str(eval(defaults[i])),214,0+i*int(222/len(defaults)),"white",eval(defaults[i]),1)
  c,s=list(newColor),0
  fill_rect(0,0,214,222,newColor)
  while not keydown(KEY_OK):
    if get_keys()!=set():
      for key in [KEY_UP,KEY_DOWN]:
        if keydown(key):
          while keydown(key):pass
          for i in [0,1]:
            if i:
              s+=(-1 if key==KEY_UP else 1)
              s%=len(defaults)
              fill_rect(214,s*int(222/len(defaults)),107,int(222/len(defaults)),'black')
            fill_rect(214+2*i,2*i+s*int(222/len(defaults)),107-4*i,int(222/len(defaults))-4*i,eval(defaults[s]))
            draw_string(str(defaults[s])+"\n"+str(eval(defaults[s])),214,s*int(222/len(defaults)),"white",eval(defaults[s]),1)
          c=list(eval(defaults[s]))
          show_col(c)
      for keys in [[KEY_VAR,KEY_TOOLBOX,KEY_BACKSPACE],[KEY_PI,KEY_SQRT,KEY_SQUARE]]:
        for key in keys:
          if keydown(key):
            c[keys.index(key)]+=(1 if key in [KEY_VAR,KEY_TOOLBOX,KEY_BACKSPACE] else -1)
            c[keys.index(key)]%=256
            show_col(c)
            sleep(.05)
      for key in [KEY_IMAGINARY,KEY_COMMA,KEY_POWER]:
        if keydown(key):
          while keydown(key):pass
          c[[KEY_IMAGINARY,KEY_COMMA,KEY_POWER].index(key)]=0
          show_col(c)
  return c
defaultsCol=['Upsilon','Omega','NW']
normalUser=True
if normalUser:
  for i in range(10):
    newCol=input('Voulez vous ajouter une autre couleur ?\n(n\'entrez rien si vous ne voulez pas):\n - ')
    if newCol=='':
      break
    else:
      defaultsCol.append(newCol)

print('Here ur color, thx for using it :D\n'+str(tuple(
pick_color((127,127,127),defaultsCol)
)),sep="")

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.