Skip to content

Instantly share code, notes, and snippets.

@knightjdr
Created August 19, 2022 19:28

Revisions

  1. knightjdr created this gist Aug 19, 2022.
    9 changes: 9 additions & 0 deletions convert_string_to_color.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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