本文整理汇总了Python中colour.Color.range_to方法的典型用法代码示例。如果您正苦于以下问题:Python Color.range_to方法的具体用法?Python Color.range_to怎么用?Python Color.range_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colour.Color
的用法示例。
在下文中一共展示了Color.range_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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: search
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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)
示例4: generate_tag_list
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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
示例5: plot_window_distribution_pie_chart
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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_colors
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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))
示例8: colors
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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
示例9: get_rainbow
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
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}
示例10: color
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [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.
"""
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()
示例11: browse_variant
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
def browse_variant(request, histone_type, variant):
try:
variant = Variant.objects.get(id=variant)
except:
return "404"
green = Color("#66c2a5")
red = Color("#fc8d62")
color_range = map(str, red.range_to(green, 12))
scores = Sequence.objects.filter(variant__id=variant).filter(all_model_scores__used_for_classifiation=True).annotate(score=Max("all_model_scores__score")).aggregate(max=Max("score"), min=Min("score"))
data = {
"core_type": variant.core_type.id,
"variant": variant.id,
"name": variant.id,
"sunburst_url": "browse/sunbursts/{}/{}.json".format(variant.core_type.id, variant.id),
"seed_file":"browse/seeds/{}/{}".format(variant.core_type.id, variant.id),
"colors":color_range,
"score_min":scores["min"],
"score_max":scores["max"],
"browse_section": "variant",
"description": variant.description,
"filter_form": AdvancedFilterForm(),
}
original_query = {"id_variant":variant.id}
if request.method == "POST":
query = request.POST.copy()
else:
query = original_query
result = HistoneSearch(request, query, reset=True)
data["original_query"] = original_query
if result.errors:
query = original_query
data["filter_errors"] = result.errors
data["current_query"] = query
return render(request, 'browse_variant.html', data)
示例12: iterateoverList
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
def iterateoverList(distribution, time, location):
print time
red = Color("red")
blue = Color("blue")
colours = list(red.range_to(blue, 100))
client = MongoClient('localhost', 27017)
db = client.hadoopOuput
collection = db['13082013']
with open(time+".css", "a") as myfile:
for tweet in collection.find({"time": time }):
for i in range(0, 100):
if tweet["type"] == "hourly":
if tweet["location"] in location:
if tweet["score"] < scoreatpercentile(distribution, i):
myfile.write("#"+tweet["location"]+"{fill:"+str(colours[i])+"}\n")
break
print "Exiting"
print ""
示例13: plotGraph
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
def plotGraph(self, g, members, numOfClus):
"""
generating the graph of vertices and edges
:param g: graph file to be plotted
:param members: vector of membership (size = # of SKUs)
:param numOfClus: number of clusters
:return: None
"""
# Setting up the ends of the spectrum
lime = Color("lime")
red = Color("red")
cols = list(red.range_to(lime, numOfClus))
cols = [str(rang).split()[0] for rang in cols]
colDict = dict(zip(range(numOfClus), cols))
print colDict
# [colDict[m] for m in members]
visual_style = {}
visual_style["vertex_size"] = 80
visual_style["vertex_shape"] = "rectangle"
visual_style["vertex_color"] = [colDict[m] for m in members] #[color_dict[gender] for gender in g.vs["gender"]]
visual_style["vertex_label"] = g.vs['name']
visual_style["edge_width"] = [w/10 for w in g.es['weight']] #[1 + 2 * int(is_formal) for is_formal in g.es["is_formal"]]
# visual_style["layout"] = layout
visual_style["bbox"] = (5500, 4000)
# visual_style["margin"] = 120
visual_style["edge_curved"] = False
plot(g, **visual_style).save(fname= 'graphClus_' +
str(self.timeThresh) + '_' +
str(self.jointViewThresh) + '_' +
str(self.pmiPerc) + '_' +
str(self.method) + '_' +
str(self.sg_lambda)) # , target="diagram.svg" layout = layout,
示例14: say
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
print 'done.'
say('ready')
# Setup the output image for the debug and gameplay windows.
output_image_width = output_card_height * cards_per_col
display_width_buffer = output_card_width
output_image_height = (output_card_width * max_number_of_cols +
display_width_buffer +
output_card_width * max_number_of_cols +
output_card_width)
gameplay_output_frame_width = 1000
# Setup a green-to-red color gradient for drawing rectangles.
red = Color('red')
lime = Color('lime')
gradient = list(red.range_to(lime, 100))
# Start the camera.
while True:
_, frame = vc.read()
if frame is not None:
# Get time for fps.
now = time.time()
# Set white threshold.
lower_white = np.array([0, 0, 255-sensitivity])
upper_white = np.array([255, sensitivity, 255])
# Set white threshold and find possible cards.
hsv_img = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
示例15: range
# 需要导入模块: from colour import Color [as 别名]
# 或者: from colour.Color import range_to [as 别名]
#initialize the sensor
sensor = adafruit_amg88xx.AMG88XX(i2c_bus)
# pylint: disable=invalid-slice-index
points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
# pylint: enable=invalid-slice-index
#sensor is an 8x8 grid so lets do a square
height = 240
width = 240
#the list of colors we can choose from
blue = Color("indigo")
colors = list(blue.range_to(Color("red"), COLORDEPTH))
#create the array of colors
colors = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in colors]
displayPixelWidth = width / 30
displayPixelHeight = height / 30
lcd = pygame.display.set_mode((width, height))
lcd.fill((255, 0, 0))
pygame.display.update()
pygame.mouse.set_visible(False)
lcd.fill((0, 0, 0))