Ejemplo n.º 1
0
        public static ColorDTO GetRandomColor()
        {
            Random   random    = new Random();
            ColorDTO randColor = new ColorDTO((byte)random.Next(0, 254),
                                              (byte)random.Next(0, 254),
                                              (byte)random.Next(0, 254));

            return(randColor);
        }
Ejemplo n.º 2
0
 public SceneConfigItem(List <LightItem> lightsUsed, ColorDTO colorUsed)
 {
     this.lightsUsed  = lightsUsed;
     this.colorDTO    = colorUsed;
     this.colorUsed   = new Color();
     this.colorUsed.A = 254;
     this.colorUsed.R = colorUsed.r;
     this.colorUsed.G = colorUsed.g;
     this.colorUsed.B = colorUsed.b;
 }
Ejemplo n.º 3
0
        public int testScene()
        {
            HueCommunicationService          hcs        = new HueCommunicationService();
            ObservableCollection <LightItem> lightItems = GetInstance().GetLightItems();

            foreach (var lightItem in lightItems)
            {
                ColorDTO nextColor = ColorDTO.GetRandomColor();
                hcs.CycleLightColor(nextColor, lightItem.LightNumber);
            }

            return(0);
        }
Ejemplo n.º 4
0
        public void CycleLightColor(ColorDTO color, int lightNum)
        {
            string uri = hueUri + userId + "/lights/" + lightNum + "/state";

            double[] colorAsXY = ConvertToColorXY(color);
            int      hue       = hueFromRGB(color);

            string data = "{ \"on\": true, \"sat\": 254, \"bri\": 254, \"hue\":"
                          + hue +
                          ",\"xy\":" + "[" + colorAsXY[0] + ", " + colorAsXY[1] + "], \"effect\": \"colorloop\" }";

            DoJSONPutRequest(uri, data);
        }
Ejemplo n.º 5
0
        private double[] ConvertToColorXY(ColorDTO color)
        {
            double[] xy = new double[2];
            double   r  = color.r / 254.0;
            double   g  = color.g / 254.0;
            double   b  = color.b / 254.0;

            r = (r > 0.04045) ? Math.Pow((r + 0.055) / (1.0f + 0.055), 2.4) : (r / 12.92);
            g = (g > 0.04045) ? Math.Pow((g + 0.055) / (1.0f + 0.055), 2.4) : (g / 12.92);
            b = (b > 0.04045) ? Math.Pow((b + 0.055) / (1.0f + 0.055), 2.4) : (b / 12.92);

            double X = r * 0.649926 + g * 0.103455 + b * 0.197109;
            double Y = r * 0.234327 + g * 0.743075 + b * 0.022598;
            double Z = r * 0.0000000 + g * 0.053077 + b * 1.035763;

            double x = X / (X + Y + Z);
            double y = Y / (X + Y + Z);

            xy[0] = x;
            xy[1] = y;
            return(xy);
        }
Ejemplo n.º 6
0
        private int hueFromRGB(ColorDTO color)
        {
            int red   = color.r;
            int green = color.g;
            int blue  = color.b;

            float min = Math.Min(Math.Min(red, green), blue);
            float max = Math.Max(Math.Max(red, green), blue);

            if (min == max)
            {
                return(0);
            }

            float hue = 0f;

            if (max == red)
            {
                hue = (green - blue) / (max - min);
            }
            else if (max == green)
            {
                hue = 2f + (blue - red) / (max - min);
            }
            else
            {
                hue = 4f + (red - green) / (max - min);
            }

            hue = hue * 60;
            if (hue < 0)
            {
                hue = hue + 360;
            }

            return((int)Math.Round(hue));
        }
Ejemplo n.º 7
0
 public ColorItem(ColorDTO color)
 {
     this.color = color;
 }