Created
August 19, 2022 19:28
-
-
Save knightjdr/aa628ecd79e6c90e4825dc382507a572 to your computer and use it in GitHub Desktop.
Convert a string in python to a hex color code
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 convert_string_to_color(str): | |
hashed = 0 | |
for i in range(len(str)): | |
hashed = ord(str[i]) + ((hashed << 5) - hashed) | |
colour = '#' | |
for i in range(3): | |
value = hashed >> i * 8 & 255 | |
colour += f'00{value:x}'[-2:] | |
return colour |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment