Created
August 6, 2013 10:29
-
-
Save SquidDev/6163422 to your computer and use it in GitHub Desktop.
Some colour functions to generate a function from the current time or from a string.
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
GenRGBColour("Pete") # Produces a colour based on Pete - generates the same colour for all Petes | |
GenRGBColour("Fred") # Same as above, but for Fred. |
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
import time, hashlib | |
def GenRGBColour(string): | |
md=hashlib.md5() | |
md.update(string) | |
HexColour=md.hexdigest() | |
return [int(HexColour[0:2], 16), int(HexColour[2:4], 16), int(HexColour[4:6], 16)] | |
def GenRandomColour(): | |
return GenRGBColour(str(time.time())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment