|
|
@@ -4,6 +4,7 @@ from PIL import Image, ImageDraw, ImageFont |
|
|
|
|
|
|
|
modes = ["base16","xresources"] |
|
|
|
RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA = 0, 60, 120, 200, 240, 300 |
|
|
|
blendTargets = ["background","foreground","accent"] |
|
|
|
|
|
|
|
parser = optparse.OptionParser(usage="usage: %prog [options] background accent [foreground]") |
|
|
|
parser.add_option("-a", "--author", |
|
|
@@ -16,6 +17,11 @@ parser.add_option("-b", "--hue-blend", |
|
|
|
dest="hueBlend", |
|
|
|
default=0.0, |
|
|
|
help="mix ratio between hues and background") |
|
|
|
parser.add_option("-B", "--hue-blend-target", |
|
|
|
action="store", |
|
|
|
dest="hueBlendTarget", |
|
|
|
default="background", |
|
|
|
help="mix ratio between hues and background") |
|
|
|
parser.add_option("-c", "--contrast", |
|
|
|
action="store", |
|
|
|
dest="foreContrast", |
|
|
@@ -57,10 +63,13 @@ base16Options.add_option("-l", "--light-brown", |
|
|
|
parser.add_option_group(base16Options) |
|
|
|
|
|
|
|
(options, args) = parser.parse_args() |
|
|
|
if options.mode not in modes: |
|
|
|
parser.error("unknown mode {}".format(options.mode)) |
|
|
|
if len(args) < 2: |
|
|
|
parser.error("need background and accent colors minimum") |
|
|
|
|
|
|
|
def dieIf(cond, message): |
|
|
|
cond and parser.error(message) |
|
|
|
|
|
|
|
dieIf(options.mode not in modes, "unknown mode \"{}\"".format(options.mode)) |
|
|
|
dieIf(len(args) < 2, "need background and accent colors minimum") |
|
|
|
dieIf(options.hueBlendTarget not in blendTargets, "unknown hue blend target \"{}\"".format(options.hueBlendTarget)) |
|
|
|
|
|
|
|
def parseTuple(st): |
|
|
|
return tuple(float(x) for x in st.split(",")) |
|
|
@@ -106,7 +115,7 @@ accentHue, accentSat = parseTuple(args[1]) |
|
|
|
|
|
|
|
foreHue, foreSat = parseTuple(args[2]) if len(args) > 2 else (0.0, 0.0) |
|
|
|
|
|
|
|
hueBlend = floatOrDie(options.hueBlend, "rainbow blend must be a number") |
|
|
|
hueBlend = floatOrDie(options.hueBlend, "hue blend must be a number") |
|
|
|
|
|
|
|
def lerp(a, b, t): |
|
|
|
return a + (b - a) * t |
|
|
@@ -160,7 +169,10 @@ def constrain(orig, compare, limit, mode=CONSTRAIN_UPPER): |
|
|
|
return lumFromContrast(compare, limit) if comp(contrast(orig, compare), limit) else orig |
|
|
|
|
|
|
|
def genRainbow(hues, minCon, maxCon): |
|
|
|
backFull = colorsys.hls_to_rgb(bgHue, 0.5, bgSat) |
|
|
|
target = {"background": (bgHue,bgSat), |
|
|
|
"foreground": (foreHue, foreSat), |
|
|
|
"accent": (accentHue, accentSat)}[options.hueBlendTarget] |
|
|
|
backFull = colorsys.hls_to_rgb(target[0], 0.5, target[1]) |
|
|
|
|
|
|
|
rainbow = [mixColors(colorsys.hls_to_rgb(hue/360.0, 0.5, 1.0), backFull, hueBlend) for hue in hues] |
|
|
|
|
|
|
@@ -182,8 +194,8 @@ def printBanner(commentChar): |
|
|
|
say("background {}: {} {} {}".format("HSL" if options.hsl else "HCL", bgHue, bgSat, origLum)) |
|
|
|
say("accent HC : {} {}".format(accentHue, accentSat)) |
|
|
|
say("foreground HC : {} {}".format(foreHue, foreSat)) |
|
|
|
say("hue blend : {}".format(hueBlend)) |
|
|
|
say("fg contrast : {}".format(foreContrast)) |
|
|
|
sayIf(hueBlend > 0.0, "hue blend : {}, with {}".format(hueBlend, options.hueBlendTarget)) |
|
|
|
sayIf(foreContrast != 7, "fg contrast : {}".format(foreContrast)) |
|
|
|
sayIf(options.equiluminant, "equiluminant hues") |
|
|
|
sayIf(options.hsl, "using gamma-encoded HSL") |
|
|
|
|
|
|
|