Created
November 18, 2014 12:30
-
-
Save narfdotpl/47120a6fca5b001fee30 to your computer and use it in GitHub Desktop.
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
def f(s): | |
return '%.3f' % (int(s, 16) / 255.0) | |
def rgb(s): | |
print '[UIColor colorWithRed:%s green:%s blue:%s alpha:1],' % \ | |
tuple(f(s.lstrip('#')[i : i + 2]) for i in range(0, 6, 2)) | |
rgb('ffffff') # [UIColor colorWithRed:1.000 green:1.000 blue:1.000 alpha:1], | |
rgb('ff0000') # [UIColor colorWithRed:1.000 green:0.000 blue:0.000 alpha:1], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment