Last active
June 23, 2023 19:17
-
-
Save kgaughan/0d8456201d33a5551682bf134e33db8d to your computer and use it in GitHub Desktop.
Python function to modify luminance of a colour
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
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