当前位置: 首页>>代码示例>>Python>>正文


Python colorsys.hls_to_rgb方法代码示例

本文整理汇总了Python中colorsys.hls_to_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python colorsys.hls_to_rgb方法的具体用法?Python colorsys.hls_to_rgb怎么用?Python colorsys.hls_to_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colorsys的用法示例。


在下文中一共展示了colorsys.hls_to_rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: random_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def random_color():
    import random, colorsys
    
    red = (random.randrange(0, 256) + 256) / 2.0;
    green = (random.randrange(0, 256) + 256) / 2.0;
    blue = (random.randrange(0, 256) + 256) / 2.0;
    
    def to_hex(i):
        hx = hex(int(i))[2:]
        if len(hx) == 1:
            hx = "0" + hx
        return hx
    def to_color(r,g,b):
        cs = [to_hex(c) for c in [r,g,b]]
        return "#{cs[0]}{cs[1]}{cs[2]}".format(cs=cs)
    def darker(r,g,b):
        h,l,s = colorsys.rgb_to_hls(r/256.0, g/256.0, b/256.0)
        cs = [to_hex(256.0*c) for c in colorsys.hls_to_rgb(h,l/2.5,s)]
        return "#{cs[0]}{cs[1]}{cs[2]}".format(cs=cs)
    
    return {"background":to_color(red,green,blue),"foreground":darker(red,green,blue)} 
开发者ID:YoannDupont,项目名称:SEM,代码行数:23,代码来源:misc.py

示例2: test_hls_values

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def test_hls_values(self):
        values = [
            # rgb, hls
            ((0.0, 0.0, 0.0), (  0  , 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (4./6., 0.5, 1.0)), # blue
            ((0.0, 1.0, 0.0), (2./6., 0.5, 1.0)), # green
            ((0.0, 1.0, 1.0), (3./6., 0.5, 1.0)), # cyan
            ((1.0, 0.0, 0.0), (  0  , 0.5, 1.0)), # red
            ((1.0, 0.0, 1.0), (5./6., 0.5, 1.0)), # purple
            ((1.0, 1.0, 0.0), (1./6., 0.5, 1.0)), # yellow
            ((1.0, 1.0, 1.0), (  0  , 1.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (  0  , 0.5, 0.0)), # grey
        ]
        for (rgb, hls) in values:
            self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb))
            self.assertTripleEqual(rgb, colorsys.hls_to_rgb(*hls)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_colorsys.py

示例3: gen_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def gen_color(self):
        """Generate a color.

        Returns:
            (int): The return value is an rgb color.
        """
        
        if self.n_assigned_colors < len(self.preferred_colors):
            hue = self.preferred_colors[self.n_assigned_colors][0]
            sat = self.preferred_colors[self.n_assigned_colors][1]
            self.n_assigned_colors += 1
        else:
            hue = random.random()
            sat = random.random()

        rgb = colorsys.hls_to_rgb(hue, self._LIGHTNESS, sat)

        return ColorCore.rgb_to_int(rgb) 
开发者ID:AirbusCyber,项目名称:grap,代码行数:20,代码来源:CryptoIdentifier.py

示例4: save

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def save(self, *args, **kwargs):
        if self.color is None:
            values = []
            for r in Resource.objects.filter(color__isnull=False):
                color = [int(r.color[i:i + 2], 16) / 255. for i in range(1, 6, 2)]
                h, _, _ = colorsys.rgb_to_hls(*color)
                values.append(h)
            values.sort()

            if values:
                prv = values[-1] - 1
            opt = 0, 0
            for val in values:
                delta, middle, prv = val - prv, (val + prv) * .5, val
                opt = max(opt, (delta, middle))
            h = opt[1] % 1
            color = colorsys.hls_to_rgb(h, .6, .5)

            self.color = '#' + ''.join(f'{int(c * 255):02x}' for c in color).upper()

        super().save(*args, **kwargs) 
开发者ID:aropan,项目名称:clist,代码行数:23,代码来源:models.py

示例5: from_hsl

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def from_hsl(h: int, s: int, l: int) -> "Color":
        """Creates a Color object from hue, saturation and luminance

        :param h: Hue
        :param s: Saturation
        :param l: Luminance
        :return: New Color object
        """
        components = (360, h, "h"), (100, l, "l"), (100, s, "s")

        for bound, component, name in components:
            if not 0 <= component <= bound:
                raise ValueError(f"{name} is outside of [0, {bound}]: {component}")

        rgb = hls_to_rgb(*(component / bound for bound, component, name in components))

        return Color(int_tuple(component * 255 for component in rgb)) 
开发者ID:BranislavBajuzik,项目名称:ColorWallpaper,代码行数:19,代码来源:Color.py

示例6: colorize

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def colorize(z):
    n, m = z.shape
    c = np.zeros((n, m, 3))
    c[np.isinf(z)] = (1.0, 1.0, 1.0)
    c[np.isnan(z)] = (0.5, 0.5, 0.5)

    idx = ~(np.isinf(z) + np.isnan(z))
    A = (np.angle(z[idx]) + np.pi) / (2*np.pi)
    A = (A + 0.5) % 1.0
    B = 1.0/(1.0 + abs(z[idx])**0.3)
    c[idx] = [hls_to_rgb(a, b, 0.8) for a, b in zip(A, B)]
    return c

###############################################################################
# Bandpass filters
# ----------------
# First, we display each wavelet according to its scale and orientation. 
开发者ID:kymatio,项目名称:kymatio,代码行数:19,代码来源:plot_filters.py

示例7: make_colors

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def make_colors(
        self, node
    ):  # return (group number, fill color, text color)
        if self.colored:
            idx, H = self.get(node)
            L = max([1.0 - 0.1 * node.get_level(), 0.1])
            S = 1.0
            A = 0.7  # make nodes translucent (to handle possible overlaps)
            fill_RGBA = self.htmlize_rgb(*colorsys.hls_to_rgb(H, L, S), A = A)

            # black text on light nodes, white text on (very) dark nodes.
            text_RGB = '#000000' if L >= 0.5 else '#ffffff'
        else:
            idx, _ = self.get(node)
            fill_RGBA = self.htmlize_rgb(1.0, 1.0, 1.0, 0.7)
            text_RGB = '#000000'
        return idx, fill_RGBA, text_RGB 
开发者ID:huseinzol05,项目名称:Python-DevOps,代码行数:19,代码来源:visgraph.py

示例8: lighten_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def lighten_color(color, amount=0.5):
    """
    Lightens the given color by multiplying (1-luminosity) by the given amount.
    Input can be matplotlib color string, hex string, or RGB tuple.

    Examples:
    >> lighten_color('g', 0.3)
    >> lighten_color('#F034A3', 0.6)
    >> lighten_color((.3,.55,.1), 0.5)
    """
    import matplotlib.colors as mc
    import colorsys
    try:
        c = mc.cnames[color]
    except:
        c = color
    c = colorsys.rgb_to_hls(*mc.to_rgb(c))
    return colorsys.hls_to_rgb(c[0], 1 - amount * (1 - c[1]), c[2]) 
开发者ID:flav-io,项目名称:flavio,代码行数:20,代码来源:colors.py

示例9: darken_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def darken_color(color, amount=0.5):
    """
    Darkens the given color by multiplying luminosity by the given amount.
    Input can be matplotlib color string, hex string, or RGB tuple.

    Examples:
    >> lighten_color('g', 0.3)
    >> lighten_color('#F034A3', 0.6)
    >> lighten_color((.3,.55,.1), 0.5)
    """
    import matplotlib.colors as mc
    import colorsys
    try:
        c = mc.cnames[color]
    except:
        c = color
    c = colorsys.rgb_to_hls(*mc.to_rgb(c))
    return colorsys.hls_to_rgb(c[0], amount * c[1], c[2]) 
开发者ID:flav-io,项目名称:flavio,代码行数:20,代码来源:colors.py

示例10: _change_color_brightness

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def _change_color_brightness(self, color, brightness_factor):
        """
        Depending on the brightness_factor, gives a lighter or darker color i.e. a color with
        less or more saturation than the original color.

        Args:
            color: color of the polygon. Refer to `matplotlib.colors` for a full list of
                formats that are accepted.
            brightness_factor (float): a value in [-1.0, 1.0] range. A lightness factor of
                0 will correspond to no change, a factor in [-1.0, 0) range will result in
                a darker color and a factor in (0, 1.0] range will result in a lighter color.

        Returns:
            modified_color (tuple[double]): a tuple containing the RGB values of the
                modified color. Each value in the tuple is in the [0.0, 1.0] range.
        """
        assert brightness_factor >= -1.0 and brightness_factor <= 1.0
        color = mplc.to_rgb(color)
        polygon_color = colorsys.rgb_to_hls(*mplc.to_rgb(color))
        modified_lightness = polygon_color[1] + (brightness_factor * polygon_color[1])
        modified_lightness = 0.0 if modified_lightness < 0.0 else modified_lightness
        modified_lightness = 1.0 if modified_lightness > 1.0 else modified_lightness
        modified_color = colorsys.hls_to_rgb(polygon_color[0], modified_lightness, polygon_color[2])
        return modified_color 
开发者ID:facebookresearch,项目名称:detectron2,代码行数:26,代码来源:visualizer.py

示例11: make_icon

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def make_icon(template, color):
        """
        Create an icon for the specified user color. It will be used to
        generate on the fly an icon representing the user.
        """
        # Get a light and dark version of the user color
        r, g, b = StatusWidget.ida_to_python(color)
        h, l, s = colorsys.rgb_to_hls(r, g, b)
        r, g, b = colorsys.hls_to_rgb(h, 0.5, 1.0)
        light = StatusWidget.python_to_qt(r, g, b)
        r, g, b = colorsys.hls_to_rgb(h, 0.25, 1.0)
        dark = StatusWidget.python_to_qt(r, g, b)

        # Replace the icon pixel with our two colors
        image = QImage(template)
        for x in range(image.width()):
            for y in range(image.height()):
                c = image.pixel(x, y)
                if (c & 0xFFFFFF) == 0xFFFFFF:
                    image.setPixel(x, y, light)
                if (c & 0xFFFFFF) == 0x000000:
                    image.setPixel(x, y, dark)
        return QPixmap(image) 
开发者ID:IDArlingTeam,项目名称:IDArling,代码行数:25,代码来源:widget.py

示例12: get_selected_fcurves_colors

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def get_selected_fcurves_colors(selected_objects_types, sepcific_obj_name='', exclude=()):
    import colorsys
    if not isinstance(selected_objects_types, Iterable):
        selected_objects_types = [selected_objects_types]
    selected_objects = [obj for obj in bpy.context.scene.objects if obj.select if
                        check_obj_type(obj.name) in selected_objects_types]
    selected_objects = [obj for obj in selected_objects if obj.animation_data is not None and
                        obj.name not in exclude][::-1]
    if len(selected_objects) == 0:
        return []
    selected_objects_len = 6 if len(selected_objects) <= 6 else len(selected_objects)
    Hs = np.linspace(0, 360, selected_objects_len + 1)[:-1] / 360
    obj_colors = [colorsys.hls_to_rgb(Hs[obj_ind], 0.5, 1) for obj_ind, obj in enumerate(selected_objects)]
    if sepcific_obj_name != '':
        selected_objects_names = [o.name for o in selected_objects]
        if sepcific_obj_name in selected_objects_names:
            return obj_colors[selected_objects_names.index(sepcific_obj_name)]
    return obj_colors 
开发者ID:pelednoam,项目名称:mmvt,代码行数:20,代码来源:mmvt_utils.py

示例13: parse_hsl

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def parse_hsl(h: str, h_units: str, sat: str, light: str, alpha: Optional[float] = None) -> RGBA:
    """
    Parse raw hue, saturation, lightness and alpha values and convert to RGBA.
    """
    s_value, l_value = parse_color_value(sat, 100), parse_color_value(light, 100)

    h_value = float(h)
    if h_units in {None, 'deg'}:
        h_value = h_value % 360 / 360
    elif h_units == 'rad':
        h_value = h_value % rads / rads
    else:
        # turns
        h_value = h_value % 1

    r, g, b = hls_to_rgb(h_value, l_value, s_value)
    return RGBA(r, g, b, alpha) 
开发者ID:samuelcolvin,项目名称:pydantic,代码行数:19,代码来源:color.py

示例14: shift

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def shift(color, amount):
  r, g, b, a = color

  print(("rgb", r, g, b, a))

  h, l, s = colorsys.rgb_to_hls(r, g, b)
  print(("hls", h, l, s))
  h *= 360
  h += int(amount)
  h %= 360
  h /= 360.0
  print(("hls", h, l, s))

  r, g, b = colorsys.hls_to_rgb(h, l, s)

  print(("rgb", int(r), int(g), int(b), a))

  return (int(r), int(g), int(b), a) 
开发者ID:ohnorobo,项目名称:pokemon,代码行数:20,代码来源:ChangeHue.py

示例15: lighten

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hls_to_rgb [as 别名]
def lighten(rgb, p):
  h,l,s = colorsys.rgb_to_hls(*(c / 255.0 for c in rgb))
  
  l = p + l - p*l
  return tuple(int(c * 255) for c in colorsys.hls_to_rgb(h,l,s)) 
开发者ID:kevinpt,项目名称:symbolator,代码行数:7,代码来源:sinebow.py


注:本文中的colorsys.hls_to_rgb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。