2 Generate a colorscheme using ColorThief.
8 from colorthief import ColorThief
11 logging.error("ColorThief wasn't found on your system.")
12 logging.error("Try another backend. (wal --backend)")
19 """Loop until 16 colors are generated."""
20 color_cmd = ColorThief(img).get_palette
22 for i in range(0, 10, 1):
23 raw_colors = color_cmd(color_count=8 + i)
25 if len(raw_colors) >= 8:
29 logging.error("ColorThief couldn't generate a suitable palette.")
33 logging.warning("ColorThief couldn't generate a palette.")
34 logging.warning("Trying a larger palette size %s", 8 + i)
36 return [util.rgb_to_hex(color) for color in raw_colors]
39 def adjust(cols, light):
41 cols.sort(key=util.rgb_to_yiq)
42 raw_colors = [*cols, *cols]
45 raw_colors[0] = util.lighten_color(cols[0], 0.90)
46 raw_colors[7] = util.darken_color(cols[0], 0.75)
49 for color in raw_colors:
50 color = util.lighten_color(color, 0.40)
52 raw_colors[0] = util.darken_color(cols[0], 0.80)
53 raw_colors[7] = util.lighten_color(cols[0], 0.60)
55 raw_colors[8] = util.lighten_color(cols[0], 0.20)
56 raw_colors[15] = raw_colors[7]
61 def get(img, light=False):
62 """Get colorscheme."""
63 cols = gen_colors(img)
64 return adjust(cols, light)