Created
July 7, 2021 06:43
-
-
Save imneonizer/5b68df7bba173a65e4e77375e0258983 to your computer and use it in GitHub Desktop.
Generate consistent random colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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