Skip to content

Instantly share code, notes, and snippets.

@kgaughan
Last active June 23, 2023 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgaughan/0d8456201d33a5551682bf134e33db8d to your computer and use it in GitHub Desktop.
Save kgaughan/0d8456201d33a5551682bf134e33db8d to your computer and use it in GitHub Desktop.
Python function to modify luminance of a colour
def modify_luminance(colour, lum=0):
rgb = 0
for i in range(0, len(colour), 2):
component = int(colour[i : i + 2], 16)
modified = round(min(max(0, component + (component * lum)), 255))
rgb = rgb * 256 + modified
return f"{rgb:0>6X}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment