xiwal

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

commit
555ff4935ee4dad738d61af2d25668e81f10e0fd
parent
14e071ac8d823b82295a58a05b8d670258d80538
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-01-28 09:45
use itertools.permutations

Diffstat

M xiwal/scheme.py 12 ++----------

1 files changed, 2 insertions, 10 deletions


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

@@ -1,4 +1,5 @@
    1     1 import functools
   -1     2 import itertools
    2     3 import math
    3     4 
    4     5 from . import lch
@@ -25,15 +26,6 @@ OFFSET = math.pi * 2 / 14
   25    26 ORDER = [0, 2, 1, 4, 5, 3]
   26    27 
   27    28 
   28    -1 def permutate(a, n):
   29    -1     if n == 0:
   30    -1         yield ()
   31    -1     else:
   32    -1         for i in range(len(a)):
   33    -1             for rest in permutate(a[:i] + a[i + 1:], n - 1):
   34    -1                 yield (a[i], *rest)
   35    -1 
   36    -1 
   37    29 @functools.lru_cache(maxsize=32)
   38    30 def distance(color, i):
   39    31     hue = math.pi / 3 * ORDER[i] + OFFSET
@@ -84,6 +76,6 @@ def scheme(colors, dominant):
   84    76 def colors2scheme(colors):
   85    77     colors = [lch.from_hex(c) for c in colors]
   86    78     dominant = colors[0]
   87    -1     colors = min(permutate(colors, 6), key=score)
   -1    79     colors = min(itertools.permutations(colors, 6), key=score)
   88    80     s = scheme(colors, dominant)
   89    81     return [lch.to_hex(c) for c in s]