def cache_all_colors():
options = {}
options['cache'] = json.load(open('color_cache.json'))
for r in range(255):
for g in range(255):
for b in range(255):
print 'r: ' + str(r) + ' | g: ' + str(g) + ' | b: ' + str(b)
desired_color = {
'r': r,
'g': g,
'b': b,
}
color_id = str(r).zfill(3) + str(g).zfill(3) + str(b).zfill(3)
closest_dist = INFINITY
closest_color_index = 0
for i, block_char in enumerate(ANSI_SHADED_BLOCKS_TO_RGB):
block_char_color = {
'r': int( block_char['r'] ),
'g': int( block_char['g'] ),
'b': int( block_char['b'] ),
}
d = color_distance(block_char_color, desired_color)
if d < closest_dist:
closest_dist = d
closest_color_index = i
# Add this index to our color cache so we don't have to look it up again
options['cache'][color_id] = closest_color_index
json.dump(options['cache'], open('color_cache.json','w'))
#@timing
评论列表
文章目录