Animatroller.Framework.LogicalDevice.Pixel1D.FadeToUsingHSV C# (CSharp) Метод

FadeToUsingHSV() публичный Метод

public FadeToUsingHSV ( int channel, Color color, double brightness, System.TimeSpan duration ) : Pixel1D
channel int
color Color
brightness double
duration System.TimeSpan
Результат Pixel1D
        public Pixel1D FadeToUsingHSV(int channel, Color color, double brightness, TimeSpan duration)
        {
            if (channel < 0 || channel >= this.pixelCount)
                throw new ArgumentOutOfRangeException();

            if (this.color[channel].GetBrightness() == 0)
            {
                this.color[channel] = color;
                this.brightness[channel] = 0;
            }

            if (color.GetBrightness() == 0)
            {
                color = this.color[channel];
                brightness = 0;
            }

            var startHSV = new HSV(this.color[channel]);
            var endHSV = new HSV(color);
            double startBrightness = this.brightness[channel];

            // 10 steps per second
            int steps = (int)(duration.TotalMilliseconds / 100);

            double position = 0;
            for (int i = 0; i < steps; i++)
            {
                double newBrightness = startBrightness + (brightness - startBrightness) * position;

                double hue = startHSV.Hue + (endHSV.Hue - startHSV.Hue) * position;
                double sat = startHSV.Saturation + (endHSV.Saturation - startHSV.Saturation) * position;
                double val = startHSV.Value + (endHSV.Value - startHSV.Value) * position;
                Color newColor = HSV.ColorFromHSV(hue, sat, val);

                SetColor(channel, newColor, newBrightness);

                System.Threading.Thread.Sleep(100);

                position += 1.0 / (steps - 1);
            }

            return this;
        }