random-stuff/hue-shades.py

39 lines
1.4 KiB
Python

#!/usr/bin/env python3
from colorsys import hsv_to_rgb
from sys import argv
from argparse import ArgumentParser,RawDescriptionHelpFormatter
parser = ArgumentParser(
description='display 24-bit "true color" shades of any HSV hue',
formatter_class=RawDescriptionHelpFormatter,
epilog="example: \n"+
"`%(prog)s 03` for orange-ish red interpreted as HSV hue of 0.03")
parser.add_argument('hue',
action='store', default="75",
nargs="?",
help='Set the hue color, fractional part of a float (the "01" in 0.01)',
type=str)
hue=parser.parse_args().hue
#fallback if argparse fails its default assignment
try: hue=float("0."+hue)
# if hue else float("0.75")
except ValueError: print("invalid hue, please use only integers!");exit()
#filler char
filler=''
for i in range(2,100,2):
for j in range(0,100):
fore=hsv_to_rgb(hue,j/100,i/100);
foreground={"red":int(fore[0]*255),"green":int(fore[1]*255),"blue":int(fore[2]*255)}
back=hsv_to_rgb(hue,j/100,(i+1)/100);
background={"red":int(back[0]*255),"green":int(back[1]*255),"blue":int(back[2]*255)}
print(
"\x1b[38;2;"+str(foreground["red"])+";"+str(foreground["green"])+";"+str(foreground["blue"])+"m"+
"\x1b[48;2;"+str(background["red"])+";"+str(background["green"])+";"+str(background["blue"])+"m"+
str(filler)+
"\x1b[0m",end='');
print("")