示例#1
0
        public (double, double, double) ColorAtDeconstruct(double location)
        {
            if (_points.Count == 0)
            {
                return(0, 0, 0);
            }

            var i = 0;
            LedColorGradientPoint start, end;

            do
            {
                start = _points[i++];
                if (i >= _points.Count)
                {
                    return(start.Color.R, start.Color.G, start.Color.B);
                }

                end = _points[i];
            } while (!(location >= start.Location && location <= end.Location));

            var correctedLocation = (location - start.Location) / (end.Location - start.Location);

            return(LedColor.LerpDeconstruct(correctedLocation, start.Color, end.Color));
        }
示例#2
0
        public static (double, double, double) LerpDeconstruct(double t, LedColor from, LedColor to)
        {
            var r = from.R * (1 - t) + to.R * t;
            var g = from.G * (1 - t) + to.G * t;
            var b = from.B * (1 - t) + to.B * t;

            return(r, g, b);
        }
示例#3
0
        public static (double, double, double) LerpSmooth(double t, LedColor from, LedColor to)
        {
            t = Math.Max(Math.Min(t, 1), 0);
            var r = from.R * (1 - t) + to.R * t;
            var g = from.G * (1 - t) + to.G * t;
            var b = from.B * (1 - t) + to.B * t;

            return(r, g, b);
        }
示例#4
0
        public static (double, double, double) ToHsv(LedColor color)
        {
            var max = Math.Max(color.R, Math.Max(color.G, color.B));
            var min = Math.Min(color.R, Math.Min(color.G, color.B));

            var delta = max - min;

            var hue = 0d;

            if (delta != 0)
            {
                if (color.R == max)
                {
                    hue = (color.G - color.B) / (double)delta;
                }
                else if (color.G == max)
                {
                    hue = 2d + (color.B - color.R) / (double)delta;
                }
                else if (color.B == max)
                {
                    hue = 4d + (color.R - color.G) / (double)delta;
                }
            }

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

            var saturation = (max == 0) ? 0 : 1d - (1d * min / max);
            var value      = max / 255d;

            return(hue, saturation, value);
        }
示例#5
0
 public static LedColor Lerp(double t, LedColor from, LedColor to)
 {
     var(r, g, b) = LerpSmooth(t, from, to);
     return(new LedColor((byte)Math.Round(r), (byte)Math.Round(g), (byte)Math.Round(b)));
 }
示例#6
0
 public (double r, double g, double b) LerpSmooth(LedColor to, double t) => LerpSmooth(t, this, to);
示例#7
0
 public LedColor Lerp(LedColor to, double t) => Lerp(t, this, to);
示例#8
0
 public static int Pack(LedColor color)
 => (color.R) | (color.G << 8) | (color.B << 16);
示例#9
0
 public static LedColor ChangeValue(LedColor color, double value)
 {
     var(h, s, _) = color.ToHsv();
     return(FromHsv(h, s, value));
 }
示例#10
0
 public static LedColor ChangeSaturation(LedColor color, double saturation)
 {
     var(h, _, v) = color.ToHsv();
     return(FromHsv(h, saturation, v));
 }
示例#11
0
 public static LedColor ChangeHue(LedColor color, double hue)
 {
     var(_, s, v) = color.ToHsv();
     return(FromHsv(hue, s, v));
 }
示例#12
0
 public static LedColor Lerp(double t, LedColor from, LedColor to)
 {
     var(r, g, b) = LerpSmooth(t, from, to);
     return(new LedColor((byte)r, (byte)g, (byte)b));
 }
示例#13
0
 public (double, double, double) LerpSmooth(LedColor to, double t) => LerpSmooth(t, this, to);
示例#14
0
 public LedColorGradientPoint(double location, LedColor color)
 {
     Location = location;
     Color    = color;
 }