Getting Started¶
Color: Color strings based on the ansicolors package.¶
Create a color by ID:
[1]:
from colorpalette import *
green = Color('forestgreen')
green
forestgreen
Color a string:
[2]:
print(green('This is green'))
This is green
Colors can also be concatenated. Add Color.reset, to remove the color code in later strings
[3]:
print(green + 'This is green' + Color.reset + '\nThis is normal')
This is green
This is normal
You can also create a color passing the foreground color (fg
), background color (bg
), style
, and define them with an ID
.
[4]:
green_lavender = Color(fg='forestgreen', bg='lavenderblush', style='underline', ID='green_lavender')
green_lavender
green_lavender
Note: Please refer to the color function in the ansicolors package for further details on these parameters:
All colors with an ID are saved in ‘cached’:
[5]:
Color.cached
[5]:
{'aliceblue': [38;2;240;248;255maliceblue[0m,
'antiquewhite': [38;2;250;235;215mantiquewhite[0m,
'aqua': [38;2;0;255;255maqua[0m,
'aquamarine': [38;2;127;255;212maquamarine[0m,
'azure': [38;2;240;255;255mazure[0m,
'beige': [38;2;245;245;220mbeige[0m,
'bisque': [38;2;255;228;196mbisque[0m,
'black': [30mblack[0m,
'blanchedalmond': [38;2;255;235;205mblanchedalmond[0m,
'blue': [34mblue[0m,
'blueviolet': [38;2;138;43;226mblueviolet[0m,
'brown': [38;2;165;42;42mbrown[0m,
'burlywood': [38;2;222;184;135mburlywood[0m,
'cadetblue': [38;2;95;158;160mcadetblue[0m,
'chartreuse': [38;2;127;255;0mchartreuse[0m,
'chocolate': [38;2;210;105;30mchocolate[0m,
'coral': [38;2;255;127;80mcoral[0m,
'cornflowerblue': [38;2;100;149;237mcornflowerblue[0m,
'cornsilk': [38;2;255;248;220mcornsilk[0m,
'crimson': [38;2;220;20;60mcrimson[0m,
'cyan': [36mcyan[0m,
'darkblue': [38;2;0;0;139mdarkblue[0m,
'darkcyan': [38;2;0;139;139mdarkcyan[0m,
'darkgoldenrod': [38;2;184;134;11mdarkgoldenrod[0m,
'darkgray': [38;2;169;169;169mdarkgray[0m,
'darkgreen': [38;2;0;100;0mdarkgreen[0m,
'darkgrey': [38;2;169;169;169mdarkgrey[0m,
'darkkhaki': [38;2;189;183;107mdarkkhaki[0m,
'darkmagenta': [38;2;139;0;139mdarkmagenta[0m,
'darkolivegreen': [38;2;85;107;47mdarkolivegreen[0m,
'darkorange': [38;2;255;140;0mdarkorange[0m,
'darkorchid': [38;2;153;50;204mdarkorchid[0m,
'darkred': [38;2;139;0;0mdarkred[0m,
'darksalmon': [38;2;233;150;122mdarksalmon[0m,
'darkseagreen': [38;2;143;188;143mdarkseagreen[0m,
'darkslateblue': [38;2;72;61;139mdarkslateblue[0m,
'darkslategray': [38;2;47;79;79mdarkslategray[0m,
'darkslategrey': [38;2;47;79;79mdarkslategrey[0m,
'darkturquoise': [38;2;0;206;209mdarkturquoise[0m,
'darkviolet': [38;2;148;0;211mdarkviolet[0m,
'deeppink': [38;2;255;20;147mdeeppink[0m,
'deepskyblue': [38;2;0;191;255mdeepskyblue[0m,
'dimgray': [38;2;105;105;105mdimgray[0m,
'dimgrey': [38;2;105;105;105mdimgrey[0m,
'dodgerblue': [38;2;30;144;255mdodgerblue[0m,
'firebrick': [38;2;178;34;34mfirebrick[0m,
'floralwhite': [38;2;255;250;240mfloralwhite[0m,
'forestgreen': [38;2;34;139;34mforestgreen[0m,
'fuchsia': [38;2;255;0;255mfuchsia[0m,
'gainsboro': [38;2;220;220;220mgainsboro[0m,
'ghostwhite': [38;2;248;248;255mghostwhite[0m,
'gold': [38;2;255;215;0mgold[0m,
'goldenrod': [38;2;218;165;32mgoldenrod[0m,
'gray': [38;2;128;128;128mgray[0m,
'green': [32mgreen[0m,
'greenyellow': [38;2;173;255;47mgreenyellow[0m,
'grey': [38;2;128;128;128mgrey[0m,
'honeydew': [38;2;240;255;240mhoneydew[0m,
'hotpink': [38;2;255;105;180mhotpink[0m,
'indianred': [38;2;205;92;92mindianred[0m,
'indigo': [38;2;75;0;130mindigo[0m,
'ivory': [38;2;255;255;240mivory[0m,
'khaki': [38;2;240;230;140mkhaki[0m,
'lavender': [38;2;230;230;250mlavender[0m,
'lavenderblush': [38;2;255;240;245mlavenderblush[0m,
'lawngreen': [38;2;124;252;0mlawngreen[0m,
'lemonchiffon': [38;2;255;250;205mlemonchiffon[0m,
'lightblue': [38;2;173;216;230mlightblue[0m,
'lightcoral': [38;2;240;128;128mlightcoral[0m,
'lightcyan': [38;2;224;255;255mlightcyan[0m,
'lightgoldenrodyellow': [38;2;250;250;210mlightgoldenrodyellow[0m,
'lightgray': [38;2;211;211;211mlightgray[0m,
'lightgreen': [38;2;144;238;144mlightgreen[0m,
'lightgrey': [38;2;211;211;211mlightgrey[0m,
'lightpink': [38;2;255;182;193mlightpink[0m,
'lightsalmon': [38;2;255;160;122mlightsalmon[0m,
'lightseagreen': [38;2;32;178;170mlightseagreen[0m,
'lightskyblue': [38;2;135;206;250mlightskyblue[0m,
'lightslategray': [38;2;119;136;153mlightslategray[0m,
'lightslategrey': [38;2;119;136;153mlightslategrey[0m,
'lightsteelblue': [38;2;176;196;222mlightsteelblue[0m,
'lightyellow': [38;2;255;255;224mlightyellow[0m,
'lime': [38;2;0;255;0mlime[0m,
'limegreen': [38;2;50;205;50mlimegreen[0m,
'linen': [38;2;250;240;230mlinen[0m,
'magenta': [35mmagenta[0m,
'maroon': [38;2;128;0;0mmaroon[0m,
'mediumaquamarine': [38;2;102;205;170mmediumaquamarine[0m,
'mediumblue': [38;2;0;0;205mmediumblue[0m,
'mediumorchid': [38;2;186;85;211mmediumorchid[0m,
'mediumpurple': [38;2;147;112;219mmediumpurple[0m,
'mediumseagreen': [38;2;60;179;113mmediumseagreen[0m,
'mediumslateblue': [38;2;123;104;238mmediumslateblue[0m,
'mediumspringgreen': [38;2;0;250;154mmediumspringgreen[0m,
'mediumturquoise': [38;2;72;209;204mmediumturquoise[0m,
'mediumvioletred': [38;2;199;21;133mmediumvioletred[0m,
'midnightblue': [38;2;25;25;112mmidnightblue[0m,
'mintcream': [38;2;245;255;250mmintcream[0m,
'mistyrose': [38;2;255;228;225mmistyrose[0m,
'moccasin': [38;2;255;228;181mmoccasin[0m,
'navajowhite': [38;2;255;222;173mnavajowhite[0m,
'navy': [38;2;0;0;128mnavy[0m,
'oldlace': [38;2;253;245;230moldlace[0m,
'olive': [38;2;128;128;0molive[0m,
'olivedrab': [38;2;107;142;35molivedrab[0m,
'orange': [38;2;255;165;0morange[0m,
'orangered': [38;2;255;69;0morangered[0m,
'orchid': [38;2;218;112;214morchid[0m,
'palegoldenrod': [38;2;238;232;170mpalegoldenrod[0m,
'palegreen': [38;2;152;251;152mpalegreen[0m,
'paleturquoise': [38;2;175;238;238mpaleturquoise[0m,
'palevioletred': [38;2;219;112;147mpalevioletred[0m,
'papayawhip': [38;2;255;239;213mpapayawhip[0m,
'peachpuff': [38;2;255;218;185mpeachpuff[0m,
'peru': [38;2;205;133;63mperu[0m,
'pink': [38;2;255;192;203mpink[0m,
'plum': [38;2;221;160;221mplum[0m,
'powderblue': [38;2;176;224;230mpowderblue[0m,
'purple': [38;2;128;0;128mpurple[0m,
'rebeccapurple': [38;2;102;51;153mrebeccapurple[0m,
'red': [31mred[0m,
'rosybrown': [38;2;188;143;143mrosybrown[0m,
'royalblue': [38;2;65;105;225mroyalblue[0m,
'saddlebrown': [38;2;139;69;19msaddlebrown[0m,
'salmon': [38;2;250;128;114msalmon[0m,
'sandybrown': [38;2;244;164;96msandybrown[0m,
'seagreen': [38;2;46;139;87mseagreen[0m,
'seashell': [38;2;255;245;238mseashell[0m,
'sienna': [38;2;160;82;45msienna[0m,
'silver': [38;2;192;192;192msilver[0m,
'skyblue': [38;2;135;206;235mskyblue[0m,
'slateblue': [38;2;106;90;205mslateblue[0m,
'slategray': [38;2;112;128;144mslategray[0m,
'slategrey': [38;2;112;128;144mslategrey[0m,
'snow': [38;2;255;250;250msnow[0m,
'springgreen': [38;2;0;255;127mspringgreen[0m,
'steelblue': [38;2;70;130;180msteelblue[0m,
'tan': [38;2;210;180;140mtan[0m,
'teal': [38;2;0;128;128mteal[0m,
'thistle': [38;2;216;191;216mthistle[0m,
'tomato': [38;2;255;99;71mtomato[0m,
'turquoise': [38;2;64;224;208mturquoise[0m,
'violet': [38;2;238;130;238mviolet[0m,
'wheat': [38;2;245;222;179mwheat[0m,
'white': [37mwhite[0m,
'whitesmoke': [38;2;245;245;245mwhitesmoke[0m,
'yellow': [33myellow[0m,
'yellowgreen': [38;2;154;205;50myellowgreen[0m,
'reset': [0mreset[0m,
'green_lavender': [38;2;34;139;34;48;2;255;240;245;4mgreen_lavender[0m}
Get RGB or HEX of the Color object:
[6]:
# Foreground color (RGB)
green_lavender.RGB
[6]:
array([ 34., 139., 34.])
[7]:
# Foreground color (normalized RGB)
green_lavender.RGBn
[7]:
array([0.13333333, 0.54509804, 0.13333333])
[8]:
# Background color (RGB)
green_lavender.RGB_bg
[8]:
array([255., 240., 245.])
[9]:
# Background color (normalized RGB)
green_lavender.RGBn_bg
[9]:
array([1. , 0.94117647, 0.96078431])
[10]:
# Foreground color (HEX)
green_lavender.HEX
[10]:
'#228b22'
[11]:
# Background color (HEX)
green_lavender.HEX_bg
[11]:
'#fff0f5'
Get tints and shades of the Color object:
[12]:
green_lavender.tint(25) # 25% tint
25% tinted green_lavender
[13]:
green_lavender.shade(25) # 25% shade
25% shaded green_lavender
Palette: Iterable set of named Color objects.¶
Create a Palette object with key/Color pairs:
[14]:
color_scheme = Palette(string=green, emphasis=green_lavender, warning=Color('red'))
color_scheme
Palette(string, emphasis, warning)
All Color objects are attributes:
[15]:
color_scheme.string, color_scheme.emphasis, color_scheme.warning
[15]:
([38;2;34;139;34mforestgreen[0m,
[38;2;34;139;34;48;2;255;240;245;4mgreen_lavender[0m,
[31mred[0m)
Palette objects are iterable:
[16]:
for color in color_scheme:
print(color('Test'))
Test
Test
Test