Skip to content

Instantly share code, notes, and snippets.

@Mause
Last active June 3, 2022 22:32
Show Gist options
  • Save Mause/4266179 to your computer and use it in GitHub Desktop.
Save Mause/4266179 to your computer and use it in GitHub Desktop.
Uses golden ratio to create pleasant/pretty colours returns in rgb form. The theory for this colour generator was taken from; http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
import math
import random
# the colorsys module is required for color conversion
from colorsys import hsv_to_rgb
# the theory for this colour generator was taken from;
# http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
def pretty_colours(how_many):
"""uses golden ratio to create pleasant/pretty colours
returns in rgb form"""
golden_ratio_conjugate = (1 + math.sqrt(5)) / 2
hue = random.random() # use random start value
final_colours = []
for tmp in range(how_many):
hue += golden_ratio_conjugate * (tmp / (5 * random.random()))
hue = hue % 1
temp_c = [round(x * 256) for x in hsv_to_rgb(hue, 0.5, 0.95)]
final_colours.append('rgb(%s, %s, %s)' % tuple(temp_c))
return final_colours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment