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
  clamped
* 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 :)
pull/1/head
Macoy Madson 3 years ago
parent
commit
c70cae7340
3 changed files with 29 additions and 18 deletions
  1. +18
    -14
      AutoBase16Theme.py
  2. +3
    -0
      Planning.org
  3. +8
    -4
      ReadMe.org

+ 18
- 14
AutoBase16Theme.py View File

@ -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
viableColors.append(color)
# 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()),
hlsColor[2])
if debugColorsVerbose:
if debugColorsVerbose and clampedColor != hlsColor:
print('Clamped {} lightness {} to {} (threshold index {})'
.format(bestColor, hlsColor[1], clampedColor[1],
currentMaximumBackgroundBrightnessThresholdIndex))
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
print(color)
rgbColor = rgbColorFromStringHex(color)
print('RGB =', rgbColor)
if debugColorsVerbose:
print(color)
rgbColor = rgbColorFromStringHex(color)
print('RGB =', rgbColor)
# Make sure we start at the darkest threshold
resetMaximumBackgroundBrightnessThresholdIndex()


+ 3
- 0
Planning.org View File

@ -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)

+ 8
- 4
ReadMe.org View File

@ -1,12 +1,17 @@
* Auto Base16 Theme
This script generates a [[https://github.com/chriskempson/base16][base16]] color theme intended for code syntax highlighting.
[[./images/Example4.jpg]]
** What it does
This script generates a [[https://github.com/chriskempson/base16][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 [[https://github.com/thefryscorer/schemer2][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 [[https://github.com/thefryscorer/schemer2][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 github.com/thefryscorer/schemer2
This script requires Python 3.
Additionally, AutoBase16Theme.py 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
[[./images/Example1.jpg]]
[[./images/Example2.jpg]]
[[./images/Example3.jpg]]
[[./images/Example4.jpg]]

Loading…
Cancel
Save