예제 #1
0
        /// <summary>
        /// Creates a color burst, starting at the given color and progressively fading to black.
        /// </summary>
        /// <param name="color">The burst color.</param>
        /// <param name="fadeoutDuration">The burst fade-out duration.</param>
        /// <param name="destinationColor">The color to progressively fade to after the color burst (black by default)</param>
        /// <returns></returns>
        public void ColorBurst(HSVColor color, LightZone zones, float fadeoutDuration = 0.15f, bool priority = true, HSVColor destinationColor = default)
        {
            LEDData data = LEDData.Empty;

            // Set all to color
            ApplyColorToZones(data, zones, color);

            SendFrame(data, zones, priority);

            // Fade to Black

            if (fadeoutDuration > 0)
            {
                if (destinationColor.Equals(HSVColor.Black))
                {
                    FadeOutToBlack(data, zones, fadeoutDuration);
                }
                else
                {
                    FadeOutToColor(data, zones, fadeoutDuration, destinationColor);
                }
            }
            else
            {
                data = LEDData.Empty;
                if (!destinationColor.Equals(HSVColor.Black))
                {
                    ApplyColorToZones(data, zones, destinationColor);
                }
                SendFrame(data, zones);
            }
        }
예제 #2
0
        // fadeoutDuration in seconds
        private void FadeOutToColor(LEDData frameData, LightZone zones, float fadeoutDuration, HSVColor color)
        {
            int          frames           = (int)Math.Round(fadeoutDuration * FPS);
            List <Led[]> frameLightArrays = frameData.GetArraysForZones(zones);

            for (int i = 0; i < frames; i++)
            {
                float        fadeout             = (float)Utils.Scale(i, 0, frames, 0, 1);
                LEDData      newFrame            = LEDData.Empty;
                List <Led[]> newFrameLightArrays = newFrame.GetArraysForZones(zones);

                for (int j = 0; j < frameLightArrays.Count; j++)
                {
                    Led[] arrCurrent = frameLightArrays[j];
                    Led[] arrNew     = newFrameLightArrays[j];
                    for (int k = 0; k < arrCurrent.Length; k++)
                    {
                        Led      l = arrCurrent[k];
                        HSVColor fadedColor;
                        if (color.Equals(HSVColor.Black))
                        {
                            fadedColor = l.color.FadeToBlackBy(fadeout);
                        }
                        else
                        {
                            fadedColor = l.color.FadeToColorBy(color, fadeout);
                        }
                        arrNew[k].Color(fadedColor);
                    }
                }
                SendFrame(newFrame, zones);
            }
        }
예제 #3
0
 /// <summary>
 /// Creates a color burst, starting at the given color and progressively fading to black.
 /// </summary>
 /// <param name="color">The burst color.</param>
 /// <param name="fadeoutRate">The burst fade-out rate.</param>
 /// <param name="destinationColor">The color to progressively fade to after the color burst (black by default)</param>
 /// <returns></returns>
 public Task ColorBurst(HSVColor color, float fadeoutRate = 0.15f, HSVColor destinationColor = default)
 {
     if (currentlyRunningAnim != null)
     {
         currentlyRunningAnim.Cancel();
     }
     currentlyRunningAnim = new CancellationTokenSource();
     //isAnimationRunning = true;
     return(TaskRunner.RunAsync(Task.Run(async() =>
     {
         CancellationToken token = currentlyRunningAnim.Token;
         foreach (Led l in this.leds)
         {
             l.Color(color);
         }
         NewFrameReady.Invoke(this, this.leds, LightingMode.Line);
         if (fadeoutRate > 0)
         {
             if (destinationColor.Equals(HSVColor.Black))
             {
                 await FadeOutToBlack(fadeoutRate, token, LightingMode.Line);
             }
             else
             {
                 await FadeOutToColor(fadeoutRate, destinationColor, token);
             }
         }
         else
         {
             if (!destinationColor.Equals(HSVColor.Black))
             {
                 this.leds.SetAllToColor(destinationColor);
             }
             else
             {
                 this.leds.SetAllToBlack();
             }
             NewFrameReady.Invoke(this, this.leds, LightingMode.Line);
         }
     })));
 }