def test_snapshot(self): for hex_color, colors in self.snapshot.items(): # Test forward functions test_rgb = hex_to_rgb(hex_color) self.assert_tuples_close(test_rgb, colors['rgb']) test_xyz = rgb_to_xyz(test_rgb) self.assert_tuples_close(test_xyz, colors['xyz']) test_luv = xyz_to_luv(test_xyz) self.assert_tuples_close(test_luv, colors['luv']) test_lch = luv_to_lch(test_luv) self.assert_tuples_close(test_lch, colors['lch']) test_hsluv = lch_to_hsluv(test_lch) self.assert_tuples_close(test_hsluv, colors['hsluv']) test_hpluv = lch_to_hpluv(test_lch) self.assert_tuples_close(test_hpluv, colors['hpluv']) # Test backward functions test_lch = hsluv_to_lch(colors['hsluv']) self.assert_tuples_close(test_lch, colors['lch']) test_lch = hpluv_to_lch(colors['hpluv']) self.assert_tuples_close(test_lch, colors['lch']) test_luv = lch_to_luv(test_lch) self.assert_tuples_close(test_luv, colors['luv']) test_xyz = luv_to_xyz(test_luv) self.assert_tuples_close(test_xyz, colors['xyz']) test_rgb = xyz_to_rgb(test_xyz) self.assert_tuples_close(test_rgb, colors['rgb']) self.assertEqual(rgb_to_hex(test_rgb), hex_color) # Full test self.assertEqual(hsluv_to_hex(colors['hsluv']), hex_color) self.assert_tuples_close(hex_to_hsluv(hex_color), colors['hsluv']) self.assertEqual(hpluv_to_hex(colors['hpluv']), hex_color) self.assert_tuples_close(hex_to_hpluv(hex_color), colors['hpluv'])
def getColorUnderCursor(): """Convert hex under cursor to color""" cursor = vim.current.window.cursor col = cursor[1] line = vim.current.line if hexcolor.match(line, col): w = line[col:col + 6] return hsluv.hex_to_hsluv("#" + w)
def hex(self, value: str) -> None: if len(value) == 4: template = "#{r}{r}{g}{g}{b}{b}" value = template.format(r=value[1], g=value[2], b=value[3]) alpha = int(value[-2:] if len(value) == 9 else "ff", 16) / 255 self.hsluva = hex_to_hsluv(value) + (alpha, )
def analyse_list(li): dh = deepcopy(li) ds = deepcopy(li) dl = deepcopy(li) for k, v in dh.items(): for k2, v2 in v.items(): # print(k, k2, v2) h, s, l = hsluv.hex_to_hsluv(v2) dh[k][k2] = h ds[k][k2] = s dl[k][k2] = l return pd.DataFrame(dh), pd.DataFrame(ds), pd.DataFrame(dl)
def generate_array(hex, type=None, num=9): # values = np.linspace(100, 0, 12) # l = np.linspace(98, 12, num) s = np.concatenate(([100], np.linspace(88, 68, num - 1, 1))) if type == "DULL": s = np.linspace(45, 35, num) l = np.linspace(98, 10, num) elif type == "BRIGHT": l = np.linspace(98, 25, num) s = np.linspace(90, 100, num) print("Lightness:", l) print("Saturation:", s) colors = [] h, _, _ = hsluv.hex_to_hsluv(hex) for s2, l2 in zip(s, l): colors.append(hsluv.hsluv_to_hex([h, s2, l2])) # print(hsluv.hpluv_to_hex(h, s, p), h, s, p) return colors
def main(argv): color = "#5ed9cd" number = 5 try: opts, args = getopt.getopt(argv, "hc:n:", ["color=", "number="]) except getopt.GetoptError: print(usage) sys.exit(2) for opt, arg in opts: if opt == '-h': print(usage) sys.exit() elif opt in ("-c", "--color"): color = '#' + arg elif opt in ("-n", "--number"): number = int(arg) refColor = hsluv.hex_to_hsluv(color) palette = [color] + generateGrowingList(refColor, number) printPalette(palette) print('') printCSS(palette)
#!/data/data/com.termux/files/usr/bin/env python3 from sys import argv, stdout, stderr import hsluv stdout.buffer.write(b"P6\n1 256\n255\n") h, s, luv = hsluv.hex_to_hsluv(argv[1]) print("\n\n\n", h, s, luv, "\n\n", file=stderr) for i in range(256): stdout.buffer.write( bytes( map( lambda x: int(x * 255 + 0.5), hsluv.hsluv_to_rgb( (h, s, ((i / 255) * 100 + ((luv - 50) / 3 if s == 0 else 0)))))))