Browse Source

Fixed pickDarkestColorForceDarkThreshold picking two of the same colors

* pickDarkestColorForceDarkThreshold() now selects colors in order of
  brightness regardless of uniqueness. This fixes the case where we
  don't know whether a color is unique because it could've gotten
* Remove duplicates from the color palette before picking
  colors. These were throwing off the algorithm
* Wrap debug code in if debug block
* Moved best example image up in the readme to make people more likely
  to read on. I did this because if you have to scroll you might not
  and miss the pretty images :)
Macoy Madson 5 years ago
  1. 32
  2. 3
  3. 12


@ -132,29 +132,30 @@ Selection heuristics
# Used for the background of dark themes. Make sure it is dark, damn it; change the color if you have to :)
def pickDarkestColorForceDarkThreshold(base16Colors, currentBase16Color, colorPool):
bestColor = None
bestColorBrightness = 10000
viableColors = []
for color in colorPool:
rgbColorBrightness = getColorBrightness(color)
if rgbColorBrightness < bestColorBrightness:
bestColor = color
bestColorBrightness = rgbColorBrightness
# Clamp brightness
if bestColor:
viableColors = sorted(viableColors,
key=lambda color: getColorBrightness(color), reverse=False)
if currentMaximumBackgroundBrightnessThresholdIndex <= len(viableColors):
bestColor = viableColors[currentMaximumBackgroundBrightnessThresholdIndex]
# Clamp brightness
hlsColor = rgb256ToHls(bestColor)
clampedColor = (hlsColor[0],
min(hlsColor[1], popMaximumBackgroundBrightnessThreshold()),
if debugColorsVerbose:
if debugColorsVerbose and clampedColor != hlsColor:
print('Clamped {} lightness {} to {} (threshold index {})'
.format(bestColor, hlsColor[1], clampedColor[1],
return hlsToRgbStringHex(clampedColor)
return bestColor
# This is weird and probably an error
return None
# Pick darkest color. If the color is already taken, pick the next unique darkest
def pickDarkestColorUnique(base16Colors, currentBase16Color, colorPool):
@ -266,16 +267,19 @@ def main():
if colorsLines:
colorPool = colorsLines
# Remove duplicate colors; these throw off the algorithm
colorPool = list(set(colorPool))
# Process color pool
for i, color in enumerate(colorPool):
# Remove newlines
colorPool[i] = color.strip('\n')
color = colorPool[i]
# For debugging
rgbColor = rgbColorFromStringHex(color)
print('RGB =', rgbColor)
if debugColorsVerbose:
rgbColor = rgbColorFromStringHex(color)
print('RGB =', rgbColor)
# Make sure we start at the darkest threshold


@ -1,3 +1,4 @@
* Left off
* To Do
** TODO Test selections with more images
** TODO Green and red tint for diff colors? Either way, establish relationship between those two (and maybe others) ensuring they are different
@ -19,3 +20,5 @@
** DONE Contrast ratio between text colors shouldn't be too great (try georgia.jpg for a bad result)
** DONE Make it so hawaii.jpg and georgia.jpg look good (don't let background get too colorful?)
*** blade2.jpg makes it seem like I need some background brightness clamping system
** DONE Fix blade1.jpg backgrounds getting clamped too hard
** DONE Fix DadSuper8Title not having some things show up (it was a duplicate color in the palette)


@ -1,12 +1,17 @@
* Auto Base16 Theme
This script generates a [[][base16]] color theme intended for code syntax highlighting.
** What it does
This script generates a [[][base16]] color theme intended for code syntax highlighting from a source image.
This means you can have *beautiful, readable* themes which match your desktop background without having to do any work.
I'm primarily focusing on doing this for Emacs, but it should work for any editor which supports base16.
** Setup
This script relies on [[][schemer2]] to choose colors from images. It then takes the output of schemer2 and selects colors which fit the base16 format. Install schemer2:
This script relies on [[][schemer2]] to choose colors from images. It then takes the output of schemer2 and selects colors which fit the base16 format. Make sure you have Go installed, then install schemer2:
: go get
This script requires Python 3.
Additionally, requires Python 3.
** How to Use
Run the following command, replacing "your image" with the image you want the theme's colors to be pulled from:
@ -17,4 +22,3 @@ Automating the execution of this so that it updates with your desktop background