Last active
September 28, 2021 14:36
-
-
Save grampabacon/8867af393c82a09b773fedc706b31a80 to your computer and use it in GitHub Desktop.
paper-cats-background-colour-gen
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 | |
# 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