Last active
February 27, 2020 23:28
-
-
Save earthmeLon/46a0e0caa371e60a4cc9f075920f87d5 to your computer and use it in GitHub Desktop.
Translate RGB colour to XY for HUE Lights
This file contains hidden or 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
#!/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