def test_alpha(self): """Test `alpha`.""" c = Color('color(--lchuv 90% 50 120 / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def test_alpha(self): """Test `alpha`.""" c = Color('color(--ictcp 1 0.2 -0.3 / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def test_alpha(self): """Test `alpha`.""" c = Color('color(xyz-d50 0.1 0.2 0.3 / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def test_alpha(self): """Test `alpha`.""" c = Color('color(--okhsl 120 50% 90% / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def test_alpha(self): """Test `alpha`.""" c = Color('color(prophoto-rgb 0.1 0.2 0.3 / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def test_alpha(self): """Test `alpha`.""" c = Color('color(--jzczhz 0.22 0.5 270 / 1)') self.assertEqual(c.alpha, 1) c.alpha = 0.5 self.assertEqual(c.alpha, 0.5)
def evaluate_contrast(string): """Evaluate color.""" colors = [] try: color = string.strip() second = None ratio = None # Try to capture the color or the two colors to mix first, ratio, more = parse_color_contrast(color) if first and more is not None: if more is False: first = None else: second, ratio, more = parse_color_contrast(color, start=first.end, second=True) if not second or more is False: first = None second = None if first: first = first.color if second: second = second.color else: if first: first = first.color second = Color("white" if first.luminance() < 0.5 else "black") # Package up the color, or the two reference colors along with the mixed. if first: colors.append(first) if second: if second.alpha < 1.0: second.alpha = 1.0 colors.append(second) if ratio: if first.alpha < 1.0: first = first.overlay(second, space="srgb") colormod = util.import_color("ColorHelper.custom.st_colormod.Color") color = colormod( "color({} min-contrast({} {}))".format( first.to_string(**util.FULL_PREC), second.to_string(**util.FULL_PREC), ratio ) ) first = Color(color) colors[0] = first if first.alpha < 1.0: # Contrasted with current color colors.append(first.overlay(second, space="srgb")) # Contrasted with the two extremes min and max colors.append(first.overlay("white", space="srgb")) colors.append(first.overlay("black", space="srgb")) else: colors.append(first.clone()) except Exception: colors = [] return colors