javascript - Philips hue, convert xy from api to HEX or RGB -
i making web interface manage hue lamps, struggling when comes color handling..
the api of lamps provides me x , y coordinates http://en.wikipedia.org/wiki/cie_1931_color_space
but not z value.
i think must calculate z brightness value or saturation value (0 255).
but terrible @ colors, , math :p.
i tried use thoses functions https://github.com/eikeon/hue-color-converter/blob/master/colorconverter.ts
but saw in comments, thoses functions not provide correct values...
could me here please ? ☺
ps : need javascript function.
okay manage make working of : how convert rgb value xy value phillips hue bulb
function xybritorgb(x, y, bri){ z = 1.0 - x - y; y = bri / 255.0; // brightness of lamp x = (y / y) * x; z = (y / y) * z; r = x * 1.612 - y * 0.203 - z * 0.302; g = -x * 0.509 + y * 1.412 + z * 0.066; b = x * 0.026 - y * 0.072 + z * 0.962; r = r <= 0.0031308 ? 12.92 * r : (1.0 + 0.055) * math.pow(r, (1.0 / 2.4)) - 0.055; g = g <= 0.0031308 ? 12.92 * g : (1.0 + 0.055) * math.pow(g, (1.0 / 2.4)) - 0.055; b = b <= 0.0031308 ? 12.92 * b : (1.0 + 0.055) * math.pow(b, (1.0 / 2.4)) - 0.055; maxvalue = math.max(r,g,b); r /= maxvalue; g /= maxvalue; b /= maxvalue; r = r * 255; if (r < 0) { r = 255 }; g = g * 255; if (g < 0) { g = 255 }; b = b * 255; if (b < 0) { b = 255 }; return { r :r, g :g, b :b } }
its not very precise, works quite well. if manage make better, please post here, thanks.
Comments
Post a Comment