Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.84 KB | None | 0 0
  1.  
  2. import math
  3. import colormath
  4. import random
  5.  
  6.  
  7. from colormath.color_objects import LabColor, XYZColor, sRGBColor, LCHabColor
  8. from colormath.color_conversions import convert_color
  9.  
  10.  
  11. def colorchanger (Ld,Cd,Hd, original_color):
  12.    
  13.     L = original_color.get_value_tuple()[0]+Ld
  14.     if (L > 100):
  15.         L=100
  16.     elif (L < 0):
  17.         L= 0
  18.        
  19.     C = original_color.get_value_tuple()[1]+Cd
  20.     if (C > 100):
  21.         C=100
  22.     elif (C < 0):
  23.         C= 0
  24.        
  25.     H = original_color.get_value_tuple()[2]+Hd
  26.    
  27.     if (H > 360):
  28.         H=H-360
  29.     elif (H < 0):
  30.         H= 360-H
  31.        
  32.  
  33.     return LCHabColor( L, C, H)
  34.    
  35. def set_color(RGB):
  36.  
  37.     fill( RGB.get_value_tuple()[0],RGB.get_value_tuple()[1],RGB.get_value_tuple()[2] )
  38.     stroke( RGB.get_value_tuple()[0],RGB.get_value_tuple()[1],RGB.get_value_tuple()[2] )
  39.  
  40.  
  41. def print_color(LCH):
  42.    
  43.     LAB = convert_color (LCH,LabColor)
  44.     RGB = convert_color (LCH,sRGBColor)
  45.    
  46.     print"LCH",round(LCH.get_value_tuple()[0],3),round(LCH.get_value_tuple()[1],3) ,round(LCH.get_value_tuple()[2])
  47.     print"LAB",round(LAB.get_value_tuple()[0],3),round(LAB.get_value_tuple()[1],3) ,round(LAB.get_value_tuple()[2])
  48.     print"RGB",RGB.get_upscaled_value_tuple()[0],RGB.get_upscaled_value_tuple()[1],RGB.get_upscaled_value_tuple()[2]
  49.  
  50.  
  51. newPage(2100, 2970)
  52. colorSpace('sRGB')
  53.  
  54. LCH = LCHabColor(58.0 , 12.0 , 29.0,observer='2', illuminant='d65')
  55.  
  56. LCH = LCHabColor(random.randint(0, 100),random.randint(0, 100),random.randint(0, 360),observer='2', illuminant='d65')
  57.  
  58.  
  59. cList = [];
  60. range_n = 5;
  61.  
  62. for x in range(0, range_n+1):
  63.    
  64.     LCH_I=sRGBColor(random.randint(0, 100)/100,random.randint(0, 100)/100,random.randint(0, 100)/100)
  65.     cList.append( LCH_I );
  66.    
  67.    
  68. start=100
  69. rect_height= 200;
  70. rect_width= 500;
  71. i=0
  72.  
  73. for RGB in cList:
  74.     set_color(RGB)
  75.     print_color(LCH)
  76.     rect(start + 0,start +  rect_height*(i*1.2)-3, rect_width, rect_height)
  77.     font("arial", 30)
  78.     fill(0,0,0 );
  79.     stroke(None);
  80.     LCH = convert_color (RGB,LCHabColor)
  81.     LAB = convert_color (RGB,LabColor)
  82.    
  83.     txt=("  LCH "+str(round(LCH.get_value_tuple()[0],3))+" , "+str(round(LCH.get_value_tuple()[1],3))+" , "+str(round(LCH.get_value_tuple()[2],3)))
  84.    
  85.     text(txt, (start + rect_width, start + rect_height*(i*1.2)-2))
  86.    
  87.     txt=("  LAB "+str(round(LAB.get_value_tuple()[0],3))+" , "+str(round(LAB.get_value_tuple()[1],3))+" , "+str(round(LAB.get_value_tuple()[2],3)))
  88.    
  89.     text(txt, (start + rect_width, start + rect_height*(i*1.2)+80))
  90.    
  91.     txt=("  RGB "+str(RGB.get_upscaled_value_tuple()[0])+" , "+str(RGB.get_upscaled_value_tuple()[1])+" , "+str(RGB.get_upscaled_value_tuple()[2])+"   "+RGB.get_rgb_hex() )
  92.          
  93.     text(txt, (start + rect_width, start + rect_height*(i*1.2)+40))
  94.    
  95.     i=i+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement