def husl_gen(): '''Generate random set of HUSL colors, one dark, one light''' hue = np.random.randint(0, 360) saturation, lightness = np.random.randint(0, 100, 2) husl_dark = husl.husl_to_hex(hue, saturation, lightness / 3) husl_light = husl.husl_to_hex(hue, saturation, lightness) return husl_dark, husl_light
def husl_gen(): '''Generate random set of HUSL colors, one dark, one light''' hue = np.random.randint(0, 360) saturation, lightness = np.random.randint(0, 100, 2) husl_dark = husl.husl_to_hex(hue, saturation, lightness/3) husl_light = husl.husl_to_hex(hue, saturation, lightness) return husl_dark, husl_light
def test_snapshot(self): for h in range(37): for s in range(21): for l in range(21): H = h * 10.0 S = s * 5.0 L = l * 5.0 test = husl.husl_to_hex(H, S, L) correct = self.snapshot['husl'][h][s][l] self.assertEqual(test, correct) test2 = husl.husl_to_hex(*husl.hex_to_husl(correct)) self.assertEqual(test2, correct)
def test_snapshot(self): for hex_color, colors in self.snapshot.items(): # Test forward functions test_rgb = husl.hex_to_rgb(hex_color) self.assertTuplesClose(test_rgb, colors['rgb']) test_xyz = husl.rgb_to_xyz(test_rgb) self.assertTuplesClose(test_xyz, colors['xyz']) test_luv = husl.xyz_to_luv(test_xyz) self.assertTuplesClose(test_luv, colors['luv']) test_lch = husl.luv_to_lch(test_luv) self.assertTuplesClose(test_lch, colors['lch']) test_husl = husl.lch_to_husl(test_lch) self.assertTuplesClose(test_husl, colors['husl']) test_huslp = husl.lch_to_huslp(test_lch) self.assertTuplesClose(test_huslp, colors['huslp']) # Test backward functions test_lch = husl.husl_to_lch(colors['husl']) self.assertTuplesClose(test_lch, colors['lch']) test_lch = husl.huslp_to_lch(colors['huslp']) self.assertTuplesClose(test_lch, colors['lch']) test_luv = husl.lch_to_luv(test_lch) self.assertTuplesClose(test_luv, colors['luv']) test_xyz = husl.luv_to_xyz(test_luv) self.assertTuplesClose(test_xyz, colors['xyz']) test_rgb = husl.xyz_to_rgb(test_xyz) self.assertTuplesClose(test_rgb, colors['rgb']) self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color) # Full test self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color) self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl']) self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color) self.assertTuplesClose(husl.hex_to_huslp(hex_color), colors['huslp'])
def update_hex_by_husl(self, event): ''' ''' color = self.labColorRep.cget('bg') huslColorHue = husl.hex_to_husl(color)[0] s, l = self.get_sl_from_entry() if s is None: return hex = husl.husl_to_hex(huslColorHue, s, l) self.labColorRep.configure(bg=hex) paletteType = self.type.get() if paletteType != 'Qualitative': if 'diverging' in paletteType: self.firstColor = str(self.firstColorSaved) self.add_color() else: self.add_color()