Created
August 13, 2018 19:13
-
-
Save MBurvill/06452a58a9d825df0b96c49e67bf1245 to your computer and use it in GitHub Desktop.
hex to RGB
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
''' | |
hex to rgb - matt burvill | |
basic premise: | |
-hex colour code is a string of always 6 characters | |
-red component is first 2 chars | |
-green is next 2 | |
-blue is final 2 | |
-int can convert hex string to interger, we can do this to each r/g/b component | |
-we divide it each component by 255 to get the decimal suitable for drawbot | |
-we pass the rgb tuple using *args | |
''' | |
myHex = "935a5a" | |
rgb = int("0x"+myHex[:2],0)/255, int("0x"+myHex[2:4],0)/255, int("0x"+myHex[4:6],0)/255 | |
print rgb | |
fill(*rgb) | |
rect(100,100,100,100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment