本文整理汇总了Python中colorsys.rgb_to_yiq方法的典型用法代码示例。如果您正苦于以下问题:Python colorsys.rgb_to_yiq方法的具体用法?Python colorsys.rgb_to_yiq怎么用?Python colorsys.rgb_to_yiq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colorsys
的用法示例。
在下文中一共展示了colorsys.rgb_to_yiq方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_yiq_values
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_yiq [as 别名]
def test_yiq_values(self):
values = [
# rgb, yiq
((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
]
for (rgb, yiq) in values:
self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
示例2: RGBToYIQ
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_yiq [as 别名]
def RGBToYIQ(red, green, blue):
return colorsys.rgb_to_yiq(
old_div(float(red), 0xff), old_div(float(green), 0xff), old_div(float(blue), 0xff))
示例3: test_yiq_roundtrip
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_yiq [as 别名]
def test_yiq_roundtrip(self):
for r in frange(0.0, 1.0, 0.2):
for g in frange(0.0, 1.0, 0.2):
for b in frange(0.0, 1.0, 0.2):
rgb = (r, g, b)
self.assertTripleEqual(
rgb,
colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
)
示例4: genColor
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_yiq [as 别名]
def genColor(n, startpoint=0):
assert n >= 1
# This splits the 0 - 1 segment in the pizza way
hue = (2 * n - 1) / (2.**(n - 1).bit_length()) - 1
hue = (hue + startpoint) % 1
# We set saturation based on the amount of green, scaled to the interval
# [0.6..0.8]. This ensures a consistent lightness over all colors.
rgb = colorsys.hsv_to_rgb(hue, 1, 1)
rgb = colorsys.hsv_to_rgb(hue, 1, (1 - rgb[1]) * 0.2 + 0.6)
# This algorithm ought to balance colors more precisely, but it overrates
# the lightness of yellow, and nearly makes it black
# yiq = colorsys.rgb_to_yiq(*rgb)
# rgb = colorsys.yiq_to_rgb(.125, yiq[1], yiq[2])
return rgb