rgb_ultra_18.py

Created by wperez274

Created on March 29, 2023

3.76 KB

Tool to learn about colors and to actually create new colors and save them ( the tuple lists [] ) Example;

DARK_GREEN = (0,155,0)

You welcome.


from math import *

from random import *
from random import randint as RAND

from kandinsky import *
from kandinsky import fill_rect as F
from kandinsky import draw_string as STR

from ion import *
from time import *


EXIT=False


BLACK=(0,)*3

RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)

DARK_RED=(125,0,0)
DARK_GREEN=(0,125,0)
DARK_BLUE=(0,0,125)



CYAN=(0,255,255)
YELLOW=(255,255,0)

WHITE=(255,)*3



RX=10
RY=10
RW=1
RH=20
RC=(0,0,0)


GX=10
GY=40
GW=1
GH=20
GC=(0,0,0)


BX=10
BY=70
BW=1
BH=20
BC=(0,0,0)



def paint_canvas():
  global RX,RY,GX,GY,BX,BY
  

  for i in range(0,255):

    fill_rect(10+i,RY,1,20,(i,0,0))
  
  for i in range(0,256):
    fill_rect(10+i,GY,1,20,(0,i,0))
  
  
  for i in range(0,256):
    fill_rect(10+i,BY,1,20,(0,0,i))
  



RC = ( get_pixel(RX,RY) ) 
GC = ( get_pixel(GX,GY) ) 
BC = ( get_pixel(BX,BY) ) 



def print_data():

  global RX,GX,BX
  
  draw_string(str(RX-10),280,RY)  
  draw_string(str(GX-10),280,GY)  
  draw_string(str(BX-10),280,BY)  

  draw_string("-(R)+ = keys:[(][)]",3,130,DARK_RED)
  draw_string("-(G)+ = keys:[*][/]",3,150,DARK_GREEN)
  draw_string("-(B)+ = keys:[+][-]",3,170,DARK_BLUE)
  draw_string("[BACKSPACE] = SELECT,EXIT,PRINT",3,108,BLACK,CYAN)


def update_data():
  
  F(275,5,42,90,CYAN)



def randomize():
    
  global RX, GX, BX

  R=RAND(0,255)
  G=RAND(0,255)
  B=RAND(0,255)
  
  
  RX=R+10
  GX=G+10
  BX=B+10
    

  F(0,0,322,222,(R,G,B))
  



#reset to gray after
#the for loops above


paint_canvas()


#RX=140
#GX=140
#BX=140
  
update_data()

while not EXIT:#keydown(KEY_BACKSPACE):




  R=RC[0]
  G=GC[1]
  B=BC[2]

  
  print_data()


  
  RC = ( get_pixel(RX,RY) ) 
  GC = ( get_pixel(GX,GY) ) 
  BC = ( get_pixel(BX,BY) ) 

  
  F(RX,RY,RW,RH,RC)
  F(GX,GY,GW,GH,GC)
  F(BX,BY,BW,BH,BC) 
  
#*************************


  
  fill_rect(RX,RY+20,1,6,(R,0,0))
  fill_rect(RX-1,RY+20,1,6,WHITE)
  fill_rect(RX+1,RY+20,1,6,WHITE)

  fill_rect(GX,GY+20,1,6,(0,G,0))
  fill_rect(GX-1,GY+20,1,6,WHITE)
  fill_rect(GX+1,GY+20,1,6,WHITE)


  fill_rect(BX,BY+20,1,6,(0,0,B))
  fill_rect(BX-1,BY+20,1,6,WHITE)
  fill_rect(BX+1,BY+20,1,6,WHITE)

  


#**********************    

  if keydown(KEY_LEFTPARENTHESIS):
    sleep(0.015)
    RX-=1
    
    update_data()


  if keydown(KEY_RIGHTPARENTHESIS):
    sleep(0.015)

    RX+=1

    update_data()


  if keydown(KEY_MULTIPLICATION):
    sleep(0.015)

    GX-=1

    update_data()


  if keydown(KEY_DIVISION):
    sleep(0.015)


    GX+=1

    update_data()


  if keydown(KEY_PLUS):
    sleep(0.015)


    BX-=1

    update_data()


  if keydown(KEY_MINUS):
    sleep(0.015)
    BX+=1

    update_data()



#rectangle

  fill_rect(210,140,90,50,(R,G,B))
#border
  fill_rect(210,140,2,50,(0,0,0))
  fill_rect(210+90-2,140,2,50,(0,0,0))
  fill_rect(210,140,90,2,(0,0,0))
  fill_rect(210,140+50-2,90,2,(0,0,0))



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

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



  if RX>10+255:
    RX=10+255

  if RX<10:
    RX=10

  if GX>10+255:
    GX=10+255

  if GX<10:
    GX=10

  if BX>10+255:
    BX=10+255

  if BX<10:
    BX=10


  print_data()


  F(0,105,322,2,BLACK)
  F(0,127,322,2,BLACK)





  if keydown(KEY_BACKSPACE):
    sleep(0.5)
    EXIT=True

    fill_rect(0,0,322,222,(0,255,255))
      
    while not keydown(KEY_OK):
      draw_string("PRESS [OK]",80,100)



  if keydown(KEY_SHIFT):
    sleep(0.14)
    randomize()
    paint_canvas()
    update_data()
    print_data()
    draw_string("bg:"+str((R,G,B)),10,200,BLACK,YELLOW)


#border main

  F(5,5,2,90,BLACK)
  F(5+265-2,5,2,90,BLACK)
  F(5,5,265,2,BLACK)
  F(5,95,265,2,BLACK)





sleep(0.5)
fill_rect(0,0,322,222,(0,255,255))
draw_string("PRESS [OK]",80,100)

print("\n NAME YOUR COLOR!! \n")

name=input("\nName: \n:")

print(name," = ",(R,G,B))

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.