1313 * https://medium.muz.li/the-science-of-color-contrast-an-expert-designers-guide-33e84c41d156
1414 * Good article on accessibility contrast calculations
1515 * Might want to use this instead of color delta calculations
16+ * https://www.w3.org/TR/WCAG20/#relativeluminancedef
17+ * How WCAG defines contrast
1618
1719 TO DO:
1820
@@ -156,6 +158,16 @@ def getAllFgBgWithDiff(delta):
156158 color = f'\033 [38;5;{ foreground } m\033 [48;5;{ background } m { foreground } on { background } \033 [0m. Contrast: { round (contrast )} '
157159 sys .stdout .write (color .ljust (4 ))
158160
161+ def printColorsByDeltaOnBg (background , delta ):
162+ print (f'Printing all foreground colors that are delta { delta } on background { background } ' )
163+ for i in range (0 , 256 ):
164+ contrast = getContrast (i , background )
165+ if contrast >= delta :
166+ foreground = str (i )
167+ _background = str (background )
168+ color = f'\033 [38;5;{ foreground } m\033 [48;5;{ _background } m { foreground } on { _background } \033 [0m. Delta: { round (delta )} '
169+ sys .stdout .write (color .ljust (4 ))
170+
159171
160172parser = argparse .ArgumentParser ()
161173subparsers = parser .add_subparsers (title = 'commands' , dest = 'command' )
@@ -179,6 +191,10 @@ def getAllFgBgWithDiff(delta):
179191printContrastParser = subparsers .add_parser ('filterContrast' , help = 'Print out all the combos that meet a given delta.' )
180192printContrastParser .add_argument ('DELTA' , type = int , help = 'Pick a color delta' )
181193
194+ printColorsByDeltaParser = subparsers .add_parser ('printGoodContrasts' , help = 'Print out all the combos on a certain bg of a specified delta.' )
195+ printColorsByDeltaParser .add_argument ('BACKGROUND' , type = int , help = 'background, must be between 0 and 255' )
196+ printColorsByDeltaParser .add_argument ('DELTA' , type = int , help = 'Delta, the specified difference level between colors' )
197+
182198
183199args = parser .parse_args ()
184200
@@ -207,5 +223,7 @@ def getAllFgBgWithDiff(delta):
207223 testForegroundOnBackground (args .COLOR1 , args .COLOR2 )
208224elif args .command == 'filterContrast' :
209225 getAllFgBgWithDiff (args .DELTA )
226+ elif args .command == 'printGoodContrasts' :
227+ printColorsByDeltaOnBg (args .BACKGROUND , args .DELTA )
210228else :
211229 parser .print_help ()
0 commit comments