Skip to content

Instantly share code, notes, and snippets.

@grampabacon
Last active September 28, 2021 14:36
Show Gist options
  • Save grampabacon/8867af393c82a09b773fedc706b31a80 to your computer and use it in GitHub Desktop.
Save grampabacon/8867af393c82a09b773fedc706b31a80 to your computer and use it in GitHub Desktop.
paper-cats-background-colour-gen
import random
# Generate a random (but bounded) RGB value, run it through the HSL algorithm
# Run recursively until we are happy that the colour looks good.
def get_background_colour():
r = random.randint(100, 255)
g = random.randint(100, 255)
b = random.randint(100, 255)
light = lightness(r, g, b)
if light <= 0.8:
return r, g, b
else:
return get_background_colour()
def lightness(r=255, g=255, b=255):
return (max(r, g, b) + min(r, g, b)) / 510.0 # HSL algorithm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment