I am making a web interface to manage my hue lamps, but i am struggling when it comes to color handling..
The api of the lamps provides me the x and y coordinates from http://en.wikipedia.org/wiki/CIE_1931_color_space
But not the z value.
I think i must calculate the z from the brightness value or saturation value (0 to 255).
but i am terrible at colors, and math :p.
I tried to use thoses functions https://github.com/eikeon/hue-color-converter/blob/master/colorconverter.ts
But as i saw in the comments, thoses functions do not provide correct values...
Could someone help me here please ? ☺
ps : i need a javascript function.
Okay so i manage to make something working with the help of : How do I convert an RGB value to a XY value for the Phillips Hue Bulb
Its not very very precise, but it works quite well. If someone manage to make something better, please post it here, thanks.
At the end it should probably be
If
r
,g
orb
is smaller than 0, shouldn't it be 0 instead of 255? The colors I tested make more sense that way. Thanks for the formula though!I modified your script to return the rgb value in HEX Notation:
And i made a PHP Version:
Happy coding to ye all :-)