Skip to content

Instantly share code, notes, and snippets.

@thundernixon
Last active January 25, 2020 04:36
Show Gist options
  • Save thundernixon/76d1c7c552fa59ff1ed82c099fbb686e to your computer and use it in GitHub Desktop.
Save thundernixon/76d1c7c552fa59ff1ed82c099fbb686e to your computer and use it in GitHub Desktop.
Use normal hex values in Drawbot
### Example of using the method in a script for Drawbot
# import the method from hexToRgb.py (have hexToRgb.py in the same folder as your script)
# alternatively, you can also just include the whole method in your code
from hex2rgb import hex2rgb
# have a hex color in mind (works with or without the # sign)
myHex = "#2F3137"
# use an asterisk to feed the tuple (R,G,B) result in place of any usual drawbot color value
fill(*hex2rgb(myHex))
# draw whatever
rect(100,100,800,800)
### simple method to convert hex color to Drawbot-compatible, 0–1 color tuple
### with help from https://stackoverflow.com/questions/29643352/converting-hex-to-rgb-value-in-python
def hex2rgb(hex):
h = hex.lstrip('#')
RGB = tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
r1, g1, b1 = RGB[0] / 255, RGB[1] / 255, RGB[2] / 255
return(r1, g1, b1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment