Ejemplo n.º 1
0
        public async Task FadeRainbow1536(uint fadeTime = 20000, float brightness = 1)
        {
            isFaidingRainbow = true;

            brightness = MathUtils.Clamp(brightness, 0f, 1f);

            //get current hue
            uint  currentHue;
            float currentBrightness;

            RGBColors.ConvertRGBToHue1536(r, g, b, out currentHue, out currentBrightness);


            uint delay        = fadeTime / 1536;
            uint stepFadeTime = delay;

            for (uint i = 0; i < 1536; i++)
            {
                if (!isFaidingRainbow)
                {
                    return;
                }

                uint hue = currentHue + i;
                if (hue >= 1536)
                {
                    hue -= 1536;
                }

                FadeHue1536(hue, brightness, stepFadeTime);
                await Task.Delay(TimeSpan.FromMilliseconds(delay));
            }
        }
Ejemplo n.º 2
0
        //return fade duration (ms)
        public uint FadeToClosestHue1536(uint maxFadeTime = 2000, float brightness = 1)
        {
            uint  currentHue;
            float currentBrightness;

            RGBColors.ConvertRGBToHue1536(r, g, b, out currentHue, out currentBrightness);

            uint transientTime = 0;

            if (currentBrightness != brightness)
            {
                float brightDiff = Math.Abs(currentBrightness - brightness);
                transientTime = (uint)(brightDiff * maxFadeTime);
            }

            uint minColor = Math.Min(r, Math.Min(g, b));

            if (minColor != 0)
            {
                uint transientTime2 = (uint)((float)minColor / 255 * maxFadeTime);
                if (transientTime2 > transientTime)
                {
                    transientTime = transientTime2;
                }
            }

            if (transientTime != 0)
            {
                FadeHue1536(currentHue, brightness, transientTime);
            }

            return(transientTime);
        }