本文整理汇总了Python中colour.Color类的典型用法代码示例。如果您正苦于以下问题:Python Color类的具体用法?Python Color怎么用?Python Color使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Color类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
def generate(self, phrase):
phrase_length = len(phrase)
# chars per color
cpc = ceil(phrase_length / self.color_count)
color_start = Color(self.start_color)
color_end = Color(self.end_color)
rainbow = list(color_start.range_to(color_end, self.color_count))
characters = list(phrase)
characters.reverse()
s = ''
for color in rainbow:
s += self.template['tag_open_before'] + color.hex + self.template['tag_open_after']
i = 0
while i < cpc and len(characters) > 0:
next_char = characters.pop()
s += next_char
i += 1
s += self.template['tag_close']
if len(characters) < 1:
break
return s
示例2: build_sunburst
def build_sunburst(sequences):
from djangophylocore.models import TaxonomyReference
import networkx as nx
from networkx.readwrite import json_graph
scores = sequences.values_list("score", flat=True)
scores_min = min(scores) if scores else 0
scores_max = max(scores) if scores else 100
green = Color("#66c2a5")
red = Color("#fc8d62")
color_range = list(red.range_to(green, 100))
def get_color_for_taxa(taxon):
avg_score = taxon.children.filter(sequence__all_model_scores__used_for_classification=True).aggregate(score=Avg("sequence__all_model_scores__score"))["score"]
avg_score = avg_score if avg_score else scores_min
scaled = int(floor((float(avg_score-scores_min)/float(scores_max-scores_min))*100))
color_index = scaled if scaled <= 99 else 99
color_index = color_index if color_index >= 0 else 0
return str(color_range[color_index])
taxa = list(sequences.values_list("taxonomy__parent__parent__parent", flat=True).distinct())
allow_ranks = ["kingdom", "phylum", "order"]
tree = TaxonomyReference().get_filtered_reference_graph(taxa, allow_ranks=allow_ranks)
nx.set_node_attributes(tree, "colour", {n:get_color_for_taxa(Taxonomy.objects.get(name=n)) for n,d in tree.out_degree_iter() if d==0})
return json_graph.tree_data(tree, "root", attrs={'children': 'children', 'id': 'name'})
示例3: generate_tag_list
def generate_tag_list(self):
memos = self.memos
if len(memos) <= 0:
return []
countHash = {}
for memo in memos:
tags = memo.tag.split(',')
for tag in tags:
s = tag.strip()
if countHash.has_key(s):
countHash[s] += 1
else:
countHash[s] = 1
tag_list = []
s = Color('#d16b16')
e = Color('#87ceed')
l = len(countHash) if len(countHash) > 1 else 2
color_list = list(s.range_to(e, l))
color_cnt = 0
max_val = max(countHash.values())
for key, val in sorted(countHash.items(),
key=lambda x:x[1],
reverse=True):
tag_dic = {}
tag_dic['name'] = key
tag_dic['size'] = (val / max_val) * 100
tag_dic['num'] = val
tag_dic['color'] = color_list[color_cnt]
color_cnt += 1
tag_list.append(tag_dic)
return tag_list
示例4: search
def search(request):
data = {"filter_form": AdvancedFilterForm()}
if request.method == "POST":
query = request.POST.copy()
else:
query = request.GET.copy()
result = HistoneSearch(query, navbar="search" in query.keys())
data["original_query"] = query
if len(result.errors) == 0:
data["result"] = True
else:
data["filter_errors"] = result.errors
if result.redirect:
return result.redirect
green = Color("#66c2a5")
red = Color("#fc8d62")
data["colors"] = map(str, red.range_to(green, 12))
data["score_min"], data["score_max"] = result.get_score_range()
return render(request, 'search.html', data)
示例5: plot_window_distribution_pie_chart
def plot_window_distribution_pie_chart(self):
"""
Plots a pie chart of how the windows used in the session.
"""
# Get data
win_distrib = self.get_time_by_active_window()
del win_distrib['total']
keys = win_distrib.keys()
values = win_distrib.values()
# Pick colors
start_color = Color("#CCE5FF")
colors = map(convert_to_hex, list(start_color.range_to(Color("#003366"), len(keys))))
# Plot pie chart
fig, ax = plt.subplots(figsize=(12,8))
ax.pie(values,
autopct='%1.0f%%',
pctdistance=1.1,
labeldistance=0.5,
shadow=True,
startangle=10,
colors=colors)
ax.set_title("Pie chart: Time spent by window")
plt.legend(keys, loc="best",shadow=True)
plt.show()
示例6: pymodoro_main
def pymodoro_main(self, i3s_output_list, i3s_config):
# Don't pass any arguments to pymodoro to avoid conflicts with
# py3status arguments
save_argv = sys.argv
sys.argv = [sys.argv[0]]
pymodoro = Pymodoro()
pymodoro.update_state()
# Get pymodoro output and remove newline
text = pymodoro.make_output().rstrip()
pymodoro.tick_sound()
# Restore argv
sys.argv = save_argv
try:
# If colour is installed, we will display a nice gradient
# from red to green depending on how many time is left
# in the current pomodoro
from colour import Color
start_c = Color(self.start_color)
end_c = Color(self.end_color)
break_c = Color(self.break_color)
if pymodoro.state == pymodoro.ACTIVE_STATE:
nb_minutes = int(
math.floor(pymodoro.config.session_duration_secs / 60)
)
colors = list(end_c.range_to(start_c, nb_minutes))
seconds_left = pymodoro.get_seconds_left()
if seconds_left is not None:
nb_minutes_left = int(math.floor(seconds_left / 60))
if nb_minutes_left >= len(colors):
nb_minutes_left = len(colors)-1
self.color = colors[nb_minutes_left].hex
else:
self.color = start_c.hex
else:
self.color = break_c.hex
except ImportError:
# If colour is not installed, use the default color
pass
response = {
'full_text': text,
'color': self.color,
# Don't cache anything
'cached_until': time.time()
}
return response
示例7: generate_branding_style_secondary
def generate_branding_style_secondary(self):
styles = dict();
if self.has_accent_color:
accent = Color(self.safe_accent_color)
accent.luminance = accent.luminance * 0.9 if accent.luminance * 0.9 >= 0 else 0;
accent.saturation = accent.saturation * 1.1 if accent.saturation * 1.1 <= 1 else 1
styles['background-color'] = accent.hex
return self.css_style(styles);
示例8: generate_colors
def generate_colors(num, from_color='#f7aabc', to_color='#404a58'):
"""
Generate `num` distinct Hexadecimal colors
"""
from_color = Color(from_color)
to_color = Color(to_color)
if num == 0:
return []
elif num == 1:
return [from_color.hex]
return list(c.hex for c in from_color.range_to(to_color, num))
示例9: colourChanged
def colourChanged(e, oldColour):
if type(e) == str:
return e
elif type(e) == Color:
nc = [e.red * 255, e.green * 255, e.blue * 255]
else:
nc = e.GetColour()
if type(oldColour) is not Color:
oldColour = Color()
oldColour.red = nc[0] / 255
oldColour.green = nc[1] / 255
oldColour.blue = nc[2] / 255
return oldColour
示例10: color_byte_array
def color_byte_array(color_value):
"""
convert color into a 3 byte bytearray
:param color_value: 6-digit (e.g. #fa3b2c), 3-digit (e.g. #fbb),
fully spelled color (e.g. white)
"""
color = Color(color_value)
return bytearray([
int(round(color.get_red()*255)),
int(round(color.get_green()*255)),
int(round(color.get_blue()*255)),
])
示例11: colors
def colors(items):
"""Create a generator which returns colors for each item in ``items``.
:param list items: The list to generate colors for.
:rtype: generator(`colour.Color <https://pypi.python.org/pypi/colour>`_)
"""
if len(items) < 2:
c = (c for c in (Color("red"),))
else:
color_from = Color("red")
color_to = Color("green")
c = (color_from.range_to(color_to, len(items)))
return c
示例12: get_rainbow
def get_rainbow(self, phrase):
phrase_length = len(phrase)
# chars per color
cpc = ceil(phrase_length / self.color_count)
color_start = Color(self.start_color)
color_end = Color(self.end_color)
rainbow = list(color_start.range_to(color_end, self.color_count))
self.rainbow = rainbow
self.cpc = cpc
# self.index = next(rainbow)
self.index = 0
return {'rainbow': rainbow, 'cpc': cpc}
示例13: poster
def poster():
# randon backgorund color
rand_rgb = tuple([(randrange(97, 160) / 255.0) for i in range(3)])
bg = Color(rgb=rand_rgb)
# get foreground
fg = Color(bg.hex)
variation = randrange(15, 60)
fg.hue = choice([variation, variation * -1])
# random alpha
alpha = randrange(4, 7) / 10.0
# create image
svg = render_template('poster.svg', bg=bg.hex, fg=fg.hex, alpha=alpha)
return Response(svg2png(bytestring=svg), mimetype='image/png')
示例14: generate_background
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)
})
示例15: color
def color(self, steps=100):
"""
Get a green -> red scoring color.
Args:
steps (int): The number of gradient steps.
Returns:
str: A hex color.
"""
r = Color('#f02424')
g = Color('#29b730')
gradient = list(r.range_to(g, steps))
idx = round(self.field('score')*(steps-1))
return gradient[idx].get_hex()