本文整理汇总了Python中colour.Color方法的典型用法代码示例。如果您正苦于以下问题:Python colour.Color方法的具体用法?Python colour.Color怎么用?Python colour.Color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colour
的用法示例。
在下文中一共展示了colour.Color方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_background
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def generate_background(self):
hue_offset = promap(int(self.hash[14:][:3], 16), 0, 4095, 0, 359)
sat_offset = int(self.hash[17:][:1], 16)
base_color = Color(hsl=(0, .42, .41))
base_color.hue = base_color.hue - hue_offset
if sat_offset % 2:
base_color.saturation = base_color.saturation + sat_offset / 100
else:
base_color.saturation = base_color.saturation - sat_offset / 100
rgb = base_color.rgb
r = int(round(rgb[0] * 255))
g = int(round(rgb[1] * 255))
b = int(round(rgb[2] * 255))
return self.svg.rect(0, 0, '100%', '100%', **{
'fill': 'rgb({}, {}, {})'.format(r, g, b)
})
示例2: plot_histories_single
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def plot_histories_single(
self, benchmarkable, ax, name=None, ylim=None, xlim=None, alpha=0.1
):
histories = []
for trial in benchmarkable.trials.trials:
histories.append(trial["result"]["history"]["elbo_test_set"])
benchmarkable.history_df = pd.DataFrame(histories).T
red = Color("red")
colors = list(red.range_to(Color("green"), benchmarkable.n_evals))
colors = [c.get_rgb() for c in colors]
benchmarkable.history_df.plot(
ax=ax,
ylim=ylim,
xlim=xlim,
color=colors,
alpha=alpha,
legend=False,
label=None,
)
name = name if name else benchmarkable.name
ax.set_title(name + " : Held-out ELBO")
ax.set_xlabel("epoch")
ax.set_xlabel("ELBO")
示例3: get_contrasting_font_color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def get_contrasting_font_color(background_color, delta=0.5):
"""
Takes in a hexcolor code and returns black or white, depending
which gives the better contrast
"""
# Return black if background_color not set
if not background_color:
return "#000000"
try:
color = Color(background_color)
except (ValueError, AttributeError):
return "#000000"
# Using Web Content Accessibility Guidelines (WCAG) 2.0 and comparing
# the background to the black color we can define which is the
# best color to improve readability on the page
# More info:
# https://www.w3.org/TR/WCAG20/
if color.luminance > delta:
return '#000000'
else:
return '#ffffff'
示例4: color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def color(self, steps=100):
"""
Get a green -> red scoring color.
Args:
steps (int): The number of gradient steps.
Returns:
str: A hex color.
"""
low = Color('#000000')
high = Color('#29b730')
gradient = list(low.range_to(high, steps))
idx = round(self.field('score')*(steps-1))
return gradient[idx].get_hex()
示例5: AskColor
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def AskColor(text="unknown graphics"):
"""
Pops up a temporary tk window asking user to visually choose a color.
Returns the chosen color as a hex string. Also prints it as text in case
the user wants to remember which color was picked and hardcode it in the script.
| __option__ | __description__
| --- | ---
| *text | an optional string to identify what purpose the color was chosen for when printing the result as text.
"""
def askcolor():
tempwindow = tk.Tk()
tempwindow.state("withdrawn")
rgb,hexcolor = tkColorChooser.askcolor(parent=tempwindow, title="choose color for "+text) ;
tempwindow.destroy()
print("you picked the following color for "+str(text)+": "+str(hexcolor))
return hexcolor
hexcolor = askcolor()
return colour.Color(hexcolor).hex
#GENERAL UTILITIES
示例6: to_serializer_format
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def to_serializer_format(cls, labels, created):
existing_shortkeys = {(label.suffix_key, label.prefix_key)
for label in created.values()}
serializer_labels = []
for label in sorted(labels):
serializer_label = {'text': label}
shortkey = cls.get_shortkey(label, existing_shortkeys)
if shortkey:
serializer_label['suffix_key'] = shortkey[0]
serializer_label['prefix_key'] = shortkey[1]
existing_shortkeys.add(shortkey)
background_color = Color(pick_for=label)
text_color = Color('white') if background_color.get_luminance() < 0.5 else Color('black')
serializer_label['background_color'] = background_color.hex
serializer_label['text_color'] = text_color.hex
serializer_labels.append(serializer_label)
return serializer_labels
示例7: colorz
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def colorz(filename, n=3):
global resizeTo
try:
img = Image.open(filename)
w, h = img.size
if w > resizeTo or h > resizeTo:
img.thumbnail((resizeTo, resizeTo))
w, h = img.size
points = get_points(img)
clusters = kmeans(points, n, 1)
rgbs = [map(int, c.center.coords) for c in clusters]
weights = [1.0*len(c.points)/(w*h) for c in clusters]
hexs = map(rtoh, rgbs)
colors = [Color(h) for h in hexs]
weighted_colors = [WeightedColor(c, weights[i]) for i,c in enumerate(colors)]
return weighted_colors
except IOError:
return []
except:
return []
示例8: parse_hex_color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def parse_hex_color(cls, color):
try:
color = Color(color).get_rgb()
return tuple(c * 255 for c in reversed(color))
except Exception:
return None
示例9: gen_image
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def gen_image(self, size, color_value):
img0 = cv.CreateImage(size, self.image_depth, self.image_channels)
if color_value == 'transparent':
color = (255, 255, 255, 255)
else:
color = self.parse_hex_color(color_value)
if not color:
raise ValueError('Color %s is not valid.' % color_value)
cv.Set(img0, color)
return img0
示例10: gen_image
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def gen_image(self, size, color_value):
if color_value == 'transparent':
color = (255, 255, 255, 255)
img = np.zeros((size[1], size[0], 4), self.image_depth)
else:
img = np.zeros((size[1], size[0], self.image_channels), self.image_depth)
color = self.parse_hex_color(color_value)
if not color:
raise ValueError('Color %s is not valid.' % color_value)
img[:] = color
return img
示例11: dimmed
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def dimmed(c):
return Color(hue=c.hue, saturation=c.saturation, luminance=c.luminance*0.6)
示例12: test_color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def test_color(self):
color = '#F5F5F5'
registry = self.init_registry(simple_column, ColumnType=Color)
test = registry.Test.insert(col=color)
assert test.col.hex == colour.Color(color).hex
示例13: test_setter_color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def test_setter_color(self):
color = '#F5F5F5'
registry = self.init_registry(simple_column, ColumnType=Color)
test = registry.Test.insert()
test.col = color
assert test.col.hex == colour.Color(color).hex
示例14: interpolate_color
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def interpolate_color(color1: str, color2: str, ratio: float) -> str:
if ratio < 0:
ratio = 0
elif ratio > 1:
ratio = 1
c1 = colour.Color(color1)
c2 = colour.Color(color2)
c3 = colour.Color(
hue=((1 - ratio) * c1.hue + ratio * c2.hue),
saturation=((1 - ratio) * c1.saturation + ratio * c2.saturation),
luminance=((1 - ratio) * c1.luminance + ratio * c2.luminance),
)
return c3.hex_l
示例15: draw_line
# 需要导入模块: import colour [as 别名]
# 或者: from colour import Color [as 别名]
def draw_line(self, p1, p2, color=None):
'''
Draw a line from p1 to p2, black to red if color is True (FIXME)
'''
r, g, b = self.colors[(NUM) % self.n_colors]
self.ctx.set_source_rgba(r, g, b, .5)
steps = int(max([abs(p2[0] - p1[0]), abs(p2[1] - p1[1])]) / ONE)
step1 = (max(p1[0], p2[0])-min(p1[0], p2[0]))/steps
step1 = -step1 if p1[0] >= p2[0] else step1
step2 = (max(p1[1], p2[1])-min(p1[1], p2[1]))/steps
step2 = -step2 if p1[1] >= p2[1] else step2
# colors = polylinear_gradient(['#0000ff','#ff0000'], steps+1)
if color:
#color = Color('black')
colors = list(Color('black').range_to(Color('red'), steps+1))
alpha = 1
else:
colors = list(Color('blue').range_to(Color('red'), steps+1))
alpha = .2
step = 0
for x, y in zip(np.arange(p1[0], p2[0], step1), np.arange(p1[1], p2[1], step2)):
self.ctx.set_source_rgba(*(colors[step].rgb + (alpha,)))
# self.ctx.set_source_rgba(
# colors['r'][step], colors['g'][step], colors['b'][step], 1)
step += 1
self.ctx.rectangle(x, y, ONE, ONE)
self.ctx.fill()