Created
February 23, 2019 08:20
-
-
Save meain/89e16a2cab92650d0564e86ccf51e718 to your computer and use it in GitHub Desktop.
This file contains 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
from colour import Color | |
def to_hex_string(color: list) -> str: | |
c = Color(hsl=tuple(color)) | |
return c.hex | |
def to_hsl(color: str): | |
color = Color(color) | |
return color.hsl | |
def get_shades(color: str, shades_count: int = 5, change_by: int = 0.1): | |
""" input: hex """ | |
hsl = to_hsl(color) | |
shades = [] | |
for i in range(shades_count): | |
shade = list(hsl) | |
shade[2] = hsl[2] + i * change_by | |
if shade[2] < 0: | |
shade[2] = 0 | |
shades.append(to_hex_string(shade)) | |
return shades | |
def get_nearby_shades(color: str): | |
lighter_shades = list(reversed(get_shades(color))) | |
darker_shades = get_shades(color, change_by=-0.1) | |
shades = lighter_shades + [color] + darker_shades | |
return shades | |
print("\n".join(get_nearby_shades("#ab00ab"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment