Exemplo n.º 1
0
        public static XYColor GetXYFromRGB(double red, double green, double blue)
        {
            //thanks to this guy https://www.reddit.com/r/tasker/comments/4mzd01/using_rgb_colours_with_philips_hue_bulbs/
            if (red > 0.04045)
            {
                red = Math.Pow((red + 0.055) / (1.0 + 0.055), 2.4);
            }
            else
            {
                red = (red / 12.92);
            }

            if (green > 0.04045)
            {
                green = Math.Pow((green + 0.055) / (1.0 + 0.055), 2.4);
            }
            else
            {
                green = (green / 12.92);
            }

            if (blue > 0.04045)
            {
                blue = Math.Pow((blue + 0.055) / (1.0 + 0.055), 2.4);
            }
            else
            {
                blue = (blue / 12.92);
            }

            var X  = red * 0.664511 + green * 0.154324 + blue * 0.162028;
            var Y  = red * 0.283881 + green * 0.668433 + blue * 0.047685;
            var Z  = red * 0.000088 + green * 0.072310 + blue * 0.986039;
            var x  = X / (X + Y + Z);
            var y  = Y / (X + Y + Z);
            var xy = new XYColor {
                X = x, Y = y
            };

            return(xy);
        }
Exemplo n.º 2
0
 public static void Breathing(ILocalHueClient client, XYColor lowColor, XYColor highColor, decimal lowBrightness, decimal highBrightness)
 {
     ChangeColor(client, 5000, 1500, highColor, highBrightness);
     ChangeColor(client, 3500, 1000, lowColor, lowBrightness);
     ChangeColor(client, 700, 500, lowColor, 0);
 }
Exemplo n.º 3
0
        private static void ChangeColor(ILocalHueClient client, int transitionMs, int msToStay, XYColor toColor, decimal brightness)
        {
            var cmd = new LightCommand()
                      .SetTransitionTime(transitionMs)
                      .SetLightColor(toColor)
                      .SetBrightness(brightness)
                      .TurnOn();

            client.SendCommandAsync(cmd);
            Thread.Sleep(transitionMs + msToStay);
        }
Exemplo n.º 4
0
        public void Breathing(XYColor lowColor, XYColor highColor, int repetitions, decimal lowBrightness, decimal highBrightness)
        {
            void breathing() => Commands.Breathing(_client, lowColor, highColor, lowBrightness, highBrightness);

            Commands.Repeater(breathing, repetitions);
        }
Exemplo n.º 5
0
 public static LightCommand SetLightColor(this LightCommand cmd, XYColor color)
 {
     cmd.SetColor(color.X, color.Y);
     return(cmd);
 }