Пример #1
0
def lighter(color, light=0.3):
	c = webcolors.html5_parse_legacy_color(color)
	
	vals = (c.red, c.green, c.blue)
	
	assert 0 < light <= 1, light
	
	vals = [int(255*light + v * (1 - light)) for v in vals]
	
	return webcolors.rgb_to_hex(webcolors.HTML5SimpleColor(*vals))
Пример #2
0
def dimmer(color, dim=0.3):
	c = webcolors.html5_parse_legacy_color(color)
	
	vals = (c.red, c.green, c.blue)
	
	assert 0 < dim <= 1, dim
	
	vals = [int(v * (1 - dim)) for v in vals]
	
	return webcolors.rgb_to_hex(webcolors.HTML5SimpleColor(*vals))
Пример #3
0
def greyit(color, pull=0.5, base=0.1):
	c = webcolors.html5_parse_legacy_color(color)
	
	vals = (c.red, c.green, c.blue)
	
	if base is not None:
		vals = [max(v, base) for v in vals]
	
	avg = sum(vals) / 3
	
	assert 0 < pull <= 1, pull
	
	vals = [max(0, min(int(pull * avg + (1 - pull) * v), 255)) for v in vals]
	
	return webcolors.rgb_to_hex(webcolors.HTML5SimpleColor(*vals))
Пример #4
0
    def test_serialize_simple_color(self):
        """
		Test implementation of the HTML5 simple color serialization
		algorithm.

		"""
        test_pairs = (
            ((0, 0, 0), "#000000"),
            ((0, 0, 128), "#000080"),
            ((218, 165, 32), "#daa520"),
            (webcolors.IntegerRGB(218, 165, 32), "#daa520"),
            (webcolors.HTML5SimpleColor(218, 165, 32), "#daa520"),
        )
        for raw, serialized in test_pairs:
            result = webcolors.html5_serialize_simple_color(raw)
            assert serialized == result
Пример #5
0
    def test_serialize_simple_color(self):
        """
        Test implementation of the HTML5 simple color serialization
        algorithm.

        """
        test_pairs = (
            ((0, 0, 0), u'#000000'),
            ((0, 0, 128), u'#000080'),
            ((218, 165, 32), u'#daa520'),
            (webcolors.IntegerRGB(218, 165, 32), u'#daa520'),
            (webcolors.HTML5SimpleColor(218, 165, 32), u'#daa520'),
        )
        for raw, serialized in test_pairs:
            self.assertEqual(serialized,
                             webcolors.html5_serialize_simple_color(raw))
Пример #6
0
def process_color(raw):
	full = webcolors.HTML5SimpleColor(*raw) if isinstance(raw, (list,tuple)) \
		else webcolors.html5_parse_legacy_color(raw)
	return webcolors.rgb_to_hex(full)