colordecoder8.py

Created by wperez274

Created on March 26, 2023

7.51 KB


from math import *
from kandinsky import *
from kandinsky import fill_rect as FILL
from kandinsky import draw_string as STR
from ion import *
from ion import keydown as GKEY
from time import *
from random import *
from random import randint as RINT




EXIT=False





rx=RINT(450,500)
ry=RINT(25,50)
rw=RINT(5,40)
rh=RINT(5,40)
rc=(RINT(0,255),RINT(0,255),RINT(0,255))

rc_2=(RINT(0,255),RINT(0,255),RINT(0,255))
rc_3=(RINT(0,255),RINT(0,255),RINT(0,255))
rc_4=(RINT(0,255),RINT(0,255),RINT(0,255))
rc_5=(RINT(0,255),RINT(0,255),RINT(0,255))


def refreshData():
  FILL(1,123,85,95,'white')


CALC_ON=True

R=RINT(0,255)
G=RINT(0,255)
B=RINT(0,255)

R_2=RINT(0,255)
G_2=RINT(0,255)
B_2=RINT(0,255)



selector_x = 5
selector_y = 183

t=0.15


tx=450

ty=100
#ty=RINT(24,100)

FILL(92,120,322-92,222-120,(0,0,0))
FILL(0,24,322,96,(R,G,B))
    

R_COPY_1=None
G_COPY_1=None
B_COPY_1=None


timer_1=0
signal_c=(RINT(40,255),RINT(40,255),RINT(40,255))


def signal():
  global timer_1,signal_c
  
  timer_1+=0.05
  
  if timer_1>=10 and timer_1<=15:
    STR("    Press [EXE] to Select Color      ",0,205,signal_c,(0,0,0))
    

        
  
  if timer_1>=RINT(20,35):
    timer_1=0
    signal_c=(RINT(40,255),RINT(40,255),RINT(40,255))

    STR("    Press [EXE] to Select Color      ",0,205,(R,G,B),(R,G,B))
  



while not EXIT:
      
  if GKEY(KEY_RIGHT) and selector_y==129:
    sleep(t)
    R+=1
    FILL(40,124,40,18,"white")
  if GKEY(KEY_LEFT) and selector_y==129:
    sleep(t)
    R-=1
    FILL(40,124,40,18,"white")
  if GKEY(KEY_RIGHT) and selector_y==147:
    sleep(t)
    G+=1
    FILL(40,142,40,18,"white")
  if GKEY(KEY_LEFT) and selector_y==147:
    sleep(t)
    G-=1
    FILL(40,142,40,18,"white")
  if GKEY(KEY_RIGHT) and selector_y==165:
    sleep(t)
    B+=1
    FILL(40,160,40,18,"white")
  if GKEY(KEY_LEFT) and selector_y==165:
    sleep(t)
    B-=1
    FILL(40,160,40,18,"white")

  if GKEY(KEY_LEFT) and selector_y==183:
    sleep(t)
    R-=1
    G-=1
    B-=1
    
  if GKEY(KEY_RIGHT) and selector_y==183:
    sleep(t)
    R+=1
    G+=1
    B+=1
    
    
    FILL(40,160,40,18,"white")



  if R>255:
    R=255
  if R<0:
    R=0
  if G>255:
    G=255
  if G<0:
    G=0
  if B>255:
    B=255
  if B<0:
    B=0

  if GKEY(KEY_DOWN) and selector_y==129:
    selector_y=147
    FILL(selector_x,124,12,12,"white")
    sleep(t)

  if GKEY(KEY_DOWN) and selector_y==147:
    selector_y=165
    FILL(selector_x,147,12,12,"white")
    sleep(t)

  if GKEY(KEY_DOWN) and selector_y==165:
    selector_y=183
    FILL(selector_x,165,12,12,"white")
    sleep(t)
  if GKEY(KEY_UP) and selector_y==183:
    selector_y=165
    FILL(selector_x,178,12,12,"white")
    sleep(t)
  if GKEY(KEY_UP) and selector_y==165:
    selector_y=147
    FILL(selector_x,160,12,12,"white")
    sleep(t)
  if GKEY(KEY_UP) and selector_y==147:
    selector_y=129
    FILL(selector_x,142,12,12,"white")
    sleep(t)

# single random R,G,B values   
#///////////////////////////////////

  if GKEY(KEY_OK) and selector_y==129:
    sleep(t)
    R=RINT(0,255)
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))

    FILL(0,24,322,96,(R,G,B))    

    FILL(38,125,32,50,"white")

  
  if GKEY(KEY_OK) and selector_y==147:
    sleep(t)
    G=RINT(0,255)
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))

    FILL(0,24,322,96,(R,G,B))    
    
    FILL(38,125,32,50,"white")

  if GKEY(KEY_OK) and selector_y==165:
    sleep(t)
    B=RINT(0,255)
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))

    FILL(0,24,322,96,(R,G,B))    
    
    FILL(38,125,32,50,"white")


  
  if GKEY(KEY_OK) and selector_y==183:
    sleep(t)
    R=RINT(0,255)
    G=RINT(0,255)
    B=RINT(0,255)
    
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))

    FILL(0,24,322,96,(R,G,B))    
    refreshData()





  if keydown(KEY_ONE):
    sleep(t)
    R=255
    G=0
    B=0
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))
    FILL(0,24,322,96,(R,G,B))    
    refreshData()



  if keydown(KEY_TWO):
    sleep(t)
    R=0
    G=255
    B=0
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))
    FILL(0,24,322,96,(R,G,B))    
    refreshData()

  if keydown(KEY_THREE):
    sleep(t)
    R=0
    B=255
    G=0
    FILL(0,0,322,24,(0,0,0))
    FILL(0,22,322,2,(0,0,255))
    FILL(0,24,322,96,(R,G,B))    
    refreshData()
 



#************************************************
#backspace resets value to zero  

  if GKEY(KEY_BACKSPACE) and selector_y==129:
    sleep(t)
    FILL(38,125,32,50,"white")
    R=0
    FILL(0,2,322,118,(R,G,B))    



  if GKEY(KEY_TOOLBOX) and selector_y==129:
    sleep(t)
    FILL(38,125,32,50,"white")
    R=255
    FILL(0,2,322,118,(R,G,B))    



 
  if GKEY(KEY_BACKSPACE) and selector_y==147:
    sleep(t)
    FILL(38,125,32,50,"white")
    G=0
    FILL(0,2,322,118,(R,G,B))    




  if GKEY(KEY_TOOLBOX) and selector_y==147:
    sleep(t)
    FILL(38,125,32,50,"white")
    G=255
    FILL(0,2,322,118,(R,G,B))    




  if GKEY(KEY_BACKSPACE) and selector_y==165:
    sleep(t)
    FILL(38,125,32,50,"white")
    B=0
    FILL(0,2,322,118,(R,G,B))    




  if GKEY(KEY_TOOLBOX) and selector_y==165:
    sleep(t)
    FILL(38,125,32,50,"white")
    B=255
    FILL(0,2,322,118,(R,G,B))    



  if GKEY(KEY_BACKSPACE) and selector_y==183:
    sleep(t)
    FILL(38,125,32,50,"white")
    R=G=B=0
    FILL(0,2,322,118,(R,G,B))    


   
  if GKEY(KEY_TOOLBOX) and selector_y==183:
    sleep(t)
    FILL(38,125,32,50,"white")
    R=G=B=255
    FILL(0,2,322,118,(R,G,B))    


  draw_string(str(bin(int(R+G+B))),tx,ty,(0,255,0),(0,0,0))





  tx-=choice([1,2,3,4,5,6,7])
  
  if tx<-160:
    tx=RINT(800,1800)


  
      

  FILL(selector_x,selector_y,6,6,"black")
  FILL(0,120,322,2,"black")
  FILL(0,0,322,2,"black")
  FILL(90,122,2,100,"black")
  STR("(OK)  = Randomize",95,125,(255,255,255),(0,0,50))
  STR("Left/Right = (-)/(+) Value",97,143,(255,255,255),(0,0,100))

  STR("Up/Down= Selector Move",97,179,(255,255,255),(0,0,200))
  STR("Backspace = Reset to 0",97,197,(255,255,255),(100,0,255))

  STR("R:"+str(R),18,124,(100,0,0))
  STR("G:"+str(G),18,142,(0,100,0))
  STR("B:"+str(B),18,160,(0,0,100))

  STR("Random",18,178,"black","cyan")
  STR("all.",18,196,"black","cyan")
  


  signal()
  

  FILL(0,24,322,96,(R,G,B))
    





  
  rx-=3
  
  if rx+rw<-5:
    rx=RINT(850,1500)
    ry=RINT(25,92-rh)
    rw=RINT(10,50)
    rh=RINT(10,50)
    
    
    rc_2=(RINT(0,255),RINT(0,255),RINT(0,255))
    rc_3=(RINT(0,255),RINT(0,255),RINT(0,255))
    rc_4=(RINT(0,255),RINT(0,255),RINT(0,255))
    rc_5=(RINT(0,255),RINT(0,255),RINT(0,255))
    

  FILL(rx,ry,rw,rh,(R,G,B))

  FILL(rx,ry,3,rh,rc_2)
  FILL(rx+rw-3,ry,3,rh,rc_3)
  FILL(rx,ry,rw,3,rc_4)
  FILL(rx,ry+rh-3,rw,3,rc_5)



  if keydown(KEY_EXE):
    EXIT=True
    mycolor=(R,G,B)
    
    
    
  if R>=255 and G<=50 and B<=50: 
    draw_string("Mostly RED",170,100,(120,0,0))

  if G>=255 and R<=50 and B<=50: 
    draw_string("Mostly GREEN",170,100,(0,120,0))

  if B>=255 and R<=50 and G<=50: 
    draw_string("Mostly BLUE",170,100,(0,0,125))



  fill_rect(0,0,322,24,(0,0,0))

  fill_rect(0,2,int(R),5,(255,0,0))
  fill_rect(0,10,int(G),5,(0,255,0))
  fill_rect(0,18,int(B),5,(0,0,255))


  draw_string(str(int(R+G+B)),275,2)
  

  rw+=RINT(-1,1)




fill_rect(0,0,322,3,(0,0,0))
fill_rect(0,0,322,222,"white")
fill_rect(0,0,322,100,(0,0,0))

fill_rect(0,100,322,35,(R,G,B))
fill_rect(0,180,322,42,(R,G,B))
draw_string("PRESS [OK] TO EXIT",40,50,'black','yellow')  

draw_string(str(mycolor),80,150)


fill_rect(0,100,322,35,(R,G,B))
fill_rect(0,180,322,42,(R,G,B))
draw_string("PRESS [OK] TO EXIT",40,50,'black','yellow')  





print(mycolor)

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.