Esempio n. 1
0
def randomColour(colourInp, num_bars, shadedBars):
    
    if(shadedBars is True):
        base = colourInp
        
        rgbl = webcolors.name_to_rgb(base)
            
        chng = 0
        if base in ['red', 'green', 'blue']:
            for i, val in enumerate(rgbl):
                if val > 0:
                    chng = i
        
        segment = int(max(rgbl)/num_bars)
        colour_list = [webcolors.rgb_to_hex(rgbl)]
        
        rgbl = list(rgbl)
        
        for vals in range(num_bars-1):
            rgbl[chng] = rgbl[chng] - segment
            
            webcolors.IntegerRGB(rgbl[0], rgbl[1], rgbl[2])
            colour_list.append(webcolors.rgb_to_hex(rgbl))
            
    else:
        colour_list = []
        
        for base in colourInp:
                
            rgbl = webcolors.name_to_rgb(base)
            
            colour_list.append(webcolors.rgb_to_hex(rgbl))
    
    return colour_list
Esempio n. 2
0
    def test_rgb_to_name(self):
        """
        Test conversion from integer RGB triplet to color name.

        """
        test_pairs = (((255, 255, 255), u'white'), ((0, 0, 128), u'navy'),
                      ((218, 165, 32), u'goldenrod'),
                      (webcolors.IntegerRGB(218, 165, 32), u'goldenrod'))

        for triplet, name in test_pairs:
            self.assertEqual(name, webcolors.rgb_to_name(triplet))
    def test_rgb_to_name(self):
        """
        Test conversion from integer RGB triplet to color name.

        """
        test_pairs = (
            ((255, 255, 255), "white"),
            ((0, 0, 128), "navy"),
            ((218, 165, 32), "goldenrod"),
            (webcolors.IntegerRGB(218, 165, 32), "goldenrod"),
        )

        for triplet, name in test_pairs:
            assert name == webcolors.rgb_to_name(triplet)
def rgb_bgr(r_color):
    """
    rgb和 bgr的互转
    参数:
        color---RGB或者BGR
    返回值:
        BGR或者RGB
    """
    r_color_list = list(r_color)
    tmp = r_color_list[0]
    r_color_list[0] = r_color_list[2]
    r_color_list[2] = tmp
    r_color = webcolors.IntegerRGB(r_color_list[0], r_color_list[1],
                                   r_color_list[2])
    return r_color
Esempio n. 5
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
Esempio n. 6
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))