Skip to content

Instantly share code, notes, and snippets.

@earthmeLon
Last active February 27, 2020 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earthmeLon/46a0e0caa371e60a4cc9f075920f87d5 to your computer and use it in GitHub Desktop.
Save earthmeLon/46a0e0caa371e60a4cc9f075920f87d5 to your computer and use it in GitHub Desktop.
Translate RGB colour to XY for HUE Lights
#!/usr/bin/env python3
def rgb_xy(red, green, blue):
red = int(red, 16)
green = int(green, 16)
blue = int(blue, 16)
x = round((red * 0.649926 + green * 0.103455 + blue * 0.197109), 6)
y = round((red * 0.234327 + green * 0.743075 + blue * 0.022598), 6)
z = round((red * 0.0000000 + green * 0.053077 + blue * 1.035763), 6)
X = round(x / (x + y + z), 4)
Y = round(y / (x + y + z), 4)
return [X, Y]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment