Created
June 1, 2013 17:23
-
-
Save anonymous/5691090 to your computer and use it in GitHub Desktop.
test
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
| # python's hex function | |
| import struct | |
| def hex_to_rgb(rgb_str): | |
| int_tuple = struct.unpack('BBB', bytes.fromhex(rgb_str)) | |
| return tuple([val/255 for val in int_tuple]) | |
| print(hex_to_rgb('f8ff35')) | |
| def hexify(color): | |
| strip_n_pad = lambda stp: str(stp[2:]).zfill(2) | |
| return "#" + "".join([strip_n_pad(hex(col)) for col in color]) | |
| print(hexify((128,128,128))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment