Created
September 26, 2021 22:36
-
-
Save AbbadonAA/2cd8fd164b5d25fac1bbd701421f0ef2 to your computer and use it in GitHub Desktop.
Pass decimal to hexadecimal RGB representation
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
def rgb(r, g, b): | |
dictionary = {0: 0, | |
1: 1, | |
2: 2, | |
3: 3, | |
4: 4, | |
5: 5, | |
6: 6, | |
7: 7, | |
8: 8, | |
9: 9, | |
10: 'A', | |
11: 'B', | |
12: 'C', | |
13: 'D', | |
14: 'E', | |
15: 'F', | |
} | |
r = (0 if r < 0 else r) and (255 if r > 255 else r) | |
g = (0 if g < 0 else g) and (255 if g > 255 else g) | |
b = (0 if b < 0 else b) and (255 if b > 255 else b) | |
r1 = f'{dictionary[int(r // 16)]}{dictionary[int(r % 16)]}' | |
g1 = f'{dictionary[int(g // 16)]}{dictionary[int(g % 16)]}' | |
b1 = f'{dictionary[int(b // 16)]}{dictionary[int(b % 16)]}' | |
return f'{r1}{g1}{b1}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment