Skip to content

Instantly share code, notes, and snippets.

@knightjdr
Created August 19, 2022 19:28
Show Gist options
  • Save knightjdr/aa628ecd79e6c90e4825dc382507a572 to your computer and use it in GitHub Desktop.
Save knightjdr/aa628ecd79e6c90e4825dc382507a572 to your computer and use it in GitHub Desktop.
Convert a string in python to a hex color code
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