def random_colors(n, seed=None):
import random
import colorsys
random.seed(seed)
# based on http://stackoverflow.com/a/470747
colors = []
for i in range(n):
hsv = (1.*i/n, 0.9 + random.random()/10, 0.9 + random.random()/10)
rgb = tuple(255*x for x in colorsys.hsv_to_rgb(*hsv))
colors.append('#%02x%02x%02x' % rgb)
return colors
# Kelly's high-contrast colors [K Kelly, Color Eng., 3 (6) (1965)],
# via http://stackoverflow.com/a/4382138. Changes: black excluded as
# not applicable here, plus some reordering (numbers in comments give
# original order).
评论列表
文章目录