Skip to content

Instantly share code, notes, and snippets.

@skiptomyliu
Last active March 11, 2017 21:41
Show Gist options
  • Save skiptomyliu/fc01b6457954e84704a775d34dd3d646 to your computer and use it in GitHub Desktop.
Save skiptomyliu/fc01b6457954e84704a775d34dd3d646 to your computer and use it in GitHub Desktop.
def luminance(r,g,b):
return math.sqrt(0.299 * math.pow(r,2) + 0.587 * math.pow(g,2) + 0.114 * math.pow(b,2))
def tint_to_lum(color, lum):
r,g,b = color
nR,nG,nB = r,g,b
while True:
tint_factor = .005
nR = nR + (255 - nR) * tint_factor
nG = nG + (255 - nG) * tint_factor
nB = nB + (255 - nB) * tint_factor
if luminance(nR,nG,nB)>=lum:
break
return int(nR), int(nG), int(nB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment