|
|
@@ -1,5 +1,5 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
import colorsys, optparse, collections |
|
|
|
import colorsys, optparse |
|
|
|
from PIL import Image, ImageDraw, ImageFont |
|
|
|
|
|
|
|
parser = optparse.OptionParser(usage="usage: %prog [options] background accent [foreground]") |
|
|
@@ -45,6 +45,9 @@ except: |
|
|
|
def lerp(a, b, t): |
|
|
|
return a + (b - a) * t |
|
|
|
|
|
|
|
def reposition(a, b, t, c, d): |
|
|
|
return lerp(c, d, (t - a) / (b - a)) |
|
|
|
|
|
|
|
def mixColors(a, b, t): |
|
|
|
return tuple(lerp(a[i], b[i], t) for i in range(3)) |
|
|
|
|
|
|
@@ -93,11 +96,17 @@ lastTwo = [lerp(foreLum, 1.0 if foreLum > bgLum else 0.0, (x + 1) / 3) for x in |
|
|
|
foreLight = makeColor(foreHue, lastTwo[0], foreSat) |
|
|
|
backLight = makeColor(bgHue, lastTwo[1], bgSat) |
|
|
|
|
|
|
|
rainHues = [0, 20, 55, 120, 180, 240, 280, 330] |
|
|
|
|
|
|
|
rainHues = [0, 20, 60, 120, 180, 240, 300, 20] |
|
|
|
backFull = colorsys.hls_to_rgb(bgHue, 0.5, bgSat) |
|
|
|
|
|
|
|
rainbow = [mixColors(colorsys.hls_to_rgb(hue/360.0, 0.5, 1.0), backFull, rainbowBlend) for hue in rainHues] |
|
|
|
rainbow = [makeColor(colorsys.rgb_to_hls(*col)[0], getContrast(bgLum, 3.5), 1.0) for col in rainbow] |
|
|
|
|
|
|
|
rainLums = [luminance(col) for col in rainbow] |
|
|
|
hiLum, loLum = max(rainLums), min(rainLums) |
|
|
|
minLum, maxLum = sorted((getContrast(bgLum, 4), getContrast(bgLum, 6))) |
|
|
|
|
|
|
|
rainHLS = [colorsys.rgb_to_hls(*col) for col in rainbow] |
|
|
|
rainbow = [makeColor(rainHLS[c][0], reposition(loLum, hiLum+0.00001, rainLums[c], minLum, maxLum) if c < 7 else minLum, rainHLS[c][2]) for c in range(len(rainbow))] |
|
|
|
|
|
|
|
cols = [background, backLighter, accent, comment, foreDark, foreground, foreLight, backLight] + rainbow |
|
|
|
|
|
|
@@ -109,21 +118,24 @@ for i in range(len(cols)): |
|
|
|
|
|
|
|
if options.showPreview: |
|
|
|
font = ImageFont.truetype("/usr/share/fonts/TTF/LiberationMono-Regular.ttf", 20) |
|
|
|
h, w = imSize = (640, 640) |
|
|
|
|
|
|
|
im = Image.new("RGB", (640, 640), usable(background)) |
|
|
|
draw = ImageDraw.Draw(im) |
|
|
|
desc = lambda t, a, b: "{} (contrast {:.1f}:1)".format(t, contrast(luminance(a), luminance(b))) |
|
|
|
text = lambda x, y, t, col, other: draw.text((x, y), desc(t, col, other), usable(col), font) |
|
|
|
|
|
|
|
draw.rectangle((2, 2, 638, 32), usable(accent)) |
|
|
|
draw.text((5, 5), "Foreground (contrast {:.1f}:1 w/ highlight)".format(contrast(luminance(foreground), luminance(accent))), usable(foreground), font) |
|
|
|
draw.text((5, 45), "Foreground (contrast {:.1f}:1 w/ background)".format(contrast(luminance(foreground), luminance(background))), usable(foreground), font) |
|
|
|
draw.text((5, 85), "# Comment color (contrast {:.1f}:1)".format(contrast(luminance(comment), luminance(background))), usable(comment), font) |
|
|
|
text(5, 5, "Foreground on highlight", foreground, accent) |
|
|
|
text(5, 45, "Foreground on background", foreground, background) |
|
|
|
text(5, 85, "# Comment color", comment, background) |
|
|
|
|
|
|
|
for i in range(len(rainbow)): |
|
|
|
draw.rectangle((4, 120+i*40, 84, 150+i*40), usable(rainbow[i])) |
|
|
|
draw.text((90, 125+i*40), "Text (contrast 3.5:1)".format(contrast(luminance(rainbow[i]), luminance(background))), usable(rainbow[i]), font) |
|
|
|
text(90, 125+i*40, "Colored text", rainbow[i], background) |
|
|
|
|
|
|
|
draw.rectangle((0, 560, 640, 600), usable(backLighter)) |
|
|
|
draw.text((5, 565), "'Dark' foreground (contrast {:.2f}:1)".format(contrast(luminance(backLighter), luminance(foreDark))), usable(foreDark), font) |
|
|
|
text(5, 565, "'Dark' foreground", foreDark, backLighter) |
|
|
|
draw.line((0, 598, 640, 598), usable(foreground), 2) |
|
|
|
|
|
|
|
for i in range(len(cols)): |
|
|
|