本文整理汇总了Python中color.Color.rgb方法的典型用法代码示例。如果您正苦于以下问题:Python Color.rgb方法的具体用法?Python Color.rgb怎么用?Python Color.rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类color.Color
的用法示例。
在下文中一共展示了Color.rgb方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_expose_event
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rgb [as 别名]
def do_expose_event(self, event):
"""
Draw the widget
"""
cr = self.window.cairo_create()
gx,gy,gw,gh = self.gradient_geometry()
grad = cairo.LinearGradient(gx,gy,gx+gw,gy)
if self.mode in "rgb":
r,g,b = [c/255.0 for c in self.color.rgb()]
r1 = r2 = r
g1 = g2 = g
b1 = b2 = b
if self.mode == 'r':
f = r
r1 = 0
r2 = 1
elif self.mode == 'g':
f = g
g1 = 0
g2 = 1
elif self.mode == 'b':
f = b
b1 = 0
b2 = 1
grad.add_color_stop_rgb(0.0, r1,g1,b1)
grad.add_color_stop_rgb(1.0, r2,g2,b2)
elif self.mode in "hsv":
col = Color()
h,s,v = self.color.hsv()
if h == 360: h = 0
if self.mode == 'h':
# this one is special...
f = h/360.
col.set_hsv(0,s,v)
max,min,tmp = [c/255. for c in col.rgb()]
grad.add_color_stop_rgb(0.0, max, min, min)
grad.add_color_stop_rgb(1/6., max, max, min)
grad.add_color_stop_rgb(2/6., min, max, min)
grad.add_color_stop_rgb(3/6., min, max, max)
grad.add_color_stop_rgb(4/6., min, min, max)
grad.add_color_stop_rgb(5/6., max, min, max)
grad.add_color_stop_rgb(1.0, max, min, min)
pass
elif self.mode == 's':
f = s
col.set_hsv(h,0,v)
r1,g1,b1 = [c/255. for c in col.rgb()]
col.set_hsv(h,1.0,v)
r2,g2,b2 = [c/255. for c in col.rgb()]
grad.add_color_stop_rgb(0.0, r1,g1,b1)
grad.add_color_stop_rgb(1.0, r2,g2,b2)
elif self.mode == 'v':
f = v
col.set_hsv(h,s,0)
r1,g1,b1 = [c/255. for c in col.rgb()]
col.set_hsv(h,s,1)
r2,g2,b2 = [c/255. for c in col.rgb()]
grad.add_color_stop_rgb(0.0, r1,g1,b1)
grad.add_color_stop_rgb(1.0, r2,g2,b2)
elif self.mode in "cmyk":
col1 = Color()
col2 = Color()
c,m,y,k = self.color.cmyk()
if self.mode == 'c':
f = c/100.
col1.set_cmyk(0,m,y,k)
col2.set_cmyk(100,m,y,k)
elif self.mode == 'm':
f = m/100.
col1.set_cmyk(c,0,y,k)
col2.set_cmyk(c,100,y,k)
elif self.mode == 'y':
f = y/100.
col1.set_cmyk(c,m,0,k)
col2.set_cmyk(c,m,100,k)
elif self.mode == 'k':
f = k/100.
col1.set_cmyk(c,m,y,0)
col2.set_cmyk(c,m,y,100)
r1,g1,b1 = [c/255. for c in col1.rgb()]
r2,g2,b2 = [c/255. for c in col2.rgb()]
grad.add_color_stop_rgb(0.0, r1,g1,b1)
grad.add_color_stop_rgb(1.0, r2,g2,b2)
# paint gradient
cr.set_source(grad)
cr.rectangle(gx,gy,gw,gh)
cr.fill()
# paint marker line
#.........这里部分代码省略.........