Skip to content

Instantly share code, notes, and snippets.

@imneonizer
Created July 7, 2021 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imneonizer/5b68df7bba173a65e4e77375e0258983 to your computer and use it in GitHub Desktop.
Save imneonizer/5b68df7bba173a65e4e77375e0258983 to your computer and use it in GitHub Desktop.
Generate consistent random colors
import random
import colorsys
def generate_colors(n):
random.seed(10101)
hsv_tuples = [(x / n, 1., 1.) for x in range(n)]
colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
colors = list(map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)), colors))
random.shuffle(colors)
random.seed(None)
return colors
if __name__ == "__main__":
generate_colors(2)
# ==== output ====
# [(0, 255, 255), (255, 0, 0)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment