Exemplo n.º 1
0
        public async Task UpdateHue(uint percent, string id, string name)
        {
            uint ret = DegreeHelper.ConvertFromDegree(percent);

            await GetLamp(id, name)?.consumer?.SetHueAsync(ret);

            FireUpdateBulb(id, name);
        }
Exemplo n.º 2
0
        public static Color ColorFromHSV(double hue, double saturation, double brightness)
        {
            hue         = DegreeHelper.ConvertToDegree((uint)hue);
            saturation /= 100;
            brightness /= 100;

            int    hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
            double f  = hue / 60 - Math.Floor(hue / 60);

            brightness = brightness * 255;
            int v = (int)Convert.ToInt64(brightness);
            int p = (int)Convert.ToInt64(brightness * (1 - saturation));
            int q = (int)Convert.ToInt64(brightness * (1 - f * saturation));
            int t = (int)Convert.ToInt64(brightness * (1 - (1 - f) * saturation));

            if (hi == 0)
            {
                return(Color.FromArgb(255, (byte)v, (byte)t, (byte)p));
            }
            else if (hi == 1)
            {
                return(Color.FromArgb(255, (byte)q, (byte)v, (byte)p));
            }
            else if (hi == 2)
            {
                return(Color.FromArgb(255, (byte)p, (byte)v, (byte)t));
            }
            else if (hi == 3)
            {
                return(Color.FromArgb(255, (byte)p, (byte)q, (byte)v));
            }
            else if (hi == 4)
            {
                return(Color.FromArgb(255, (byte)t, (byte)p, (byte)v));
            }
            else
            {
                return(Color.FromArgb(255, (byte)v, (byte)p, (byte)q));
            }
        }