xiwal

Generate terminal color schemes
git clone https://git.ce9e.org/xiwal.git

commit
fde244a9d8cefb2b807c2807beebc4a7282fb98d
parent
6098e30ef537467a3eecdec0e80c1fe8608e1b3e
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-11-15 08:42
move some magic numbers into constants

Diffstat

M wal/scheme.py 15 +++++++++++----

1 files changed, 11 insertions, 4 deletions


diff --git a/wal/scheme.py b/wal/scheme.py

@@ -5,6 +5,11 @@ from . import lch
    5     5 # Minimum chroma for red/green (signal colors)
    6     6 C_RG = 60
    7     7 
   -1     8 # MAXIMUM chroma for greys
   -1     9 C_GREY = 8
   -1    10 
   -1    11 C_FACTOR = 1.2
   -1    12 
    8    13 # lightness for dark/light colors
    9    14 # Some general guidelines:
   10    15 # - dark kcolors should have sufficient contrast to both black and white
@@ -18,6 +23,7 @@ OFFSET = math.pi * 2 / 15
   18    23 
   19    24 ORDER = [0, 2, 1, 4, 5, 3]
   20    25 
   -1    26 
   21    27 def permutate(a, n):
   22    28 	if n == 0:
   23    29 		yield ()
@@ -50,11 +56,11 @@ def score(colors):
   50    56 
   51    57 
   52    58 def scheme(colors, dominant):
   53    -1 	c_grey = min(dominant[1], 8)
   -1    59 	c_grey = min(dominant[1], C_GREY)
   54    60 
   55    61 	yield L_DARK[0], c_grey, dominant[2]
   56    62 	for i in range(6):
   57    -1 		c = colors[i][1] * 1.2
   -1    63 		c = colors[i][1] * C_FACTOR
   58    64 		if i in [0, 1]:
   59    65 			c = max(c, C_RG)
   60    66 		yield L_DARK[i + 1], c, colors[i][2]
@@ -62,7 +68,7 @@ def scheme(colors, dominant):
   62    68 
   63    69 	yield L_LIGHT[0], c_grey, dominant[2]
   64    70 	for i in range(6):
   65    -1 		c = colors[i][1] * 1.2
   -1    71 		c = colors[i][1] * C_FACTOR
   66    72 		if i in [0, 1]:
   67    73 			c = max(c, C_RG)
   68    74 		yield L_LIGHT[i + 1], c, colors[i][2]
@@ -73,4 +79,5 @@ def colors2scheme(colors):
   73    79 	colors = [lch.from_hex(c) for c in colors]
   74    80 	dominant = colors[0]
   75    81 	colors = min(permutate(colors, 6), key=score)
   76    -1 	return [lch.to_hex(c) for c in scheme(colors, dominant)]
   -1    82 	s = scheme(colors, dominant)
   -1    83 	return [lch.to_hex(c) for c in s]