Skip to content

Instantly share code, notes, and snippets.

@MBurvill
Created August 13, 2018 19:13
Show Gist options
  • Save MBurvill/06452a58a9d825df0b96c49e67bf1245 to your computer and use it in GitHub Desktop.
Save MBurvill/06452a58a9d825df0b96c49e67bf1245 to your computer and use it in GitHub Desktop.
hex to RGB
'''
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