Exemplo n.º 1
0
        public IColor GetColor(float position)
        {
            int i;

            for (i = 0; i < _gradientPoints.Count; i++)
            {
                GradientPoint gradientPoint = _gradientPoints[i];
                if (position < gradientPoint.Position)
                {
                    break;
                }
            }
            int num  = Libnoise.Clamp(i - 1, 0, _gradientPoints.Count - 1);
            int num2 = Libnoise.Clamp(i, 0, _gradientPoints.Count - 1);

            if (num == num2)
            {
                GradientPoint gradientPoint2 = _gradientPoints[num2];
                return(gradientPoint2.Color);
            }
            GradientPoint gradientPoint3 = _gradientPoints[num];
            float         position2      = gradientPoint3.Position;
            GradientPoint gradientPoint4 = _gradientPoints[num2];
            float         position3      = gradientPoint4.Position;
            float         num3           = (position - position2) / (position3 - position2);
            GradientPoint gradientPoint5 = _gradientPoints[num];
            IColor        color          = gradientPoint5.Color;
            GradientPoint gradientPoint6 = _gradientPoints[num2];

            return(Color.Lerp(color, gradientPoint6.Color, num3));
        }
Exemplo n.º 2
0
 public void AddGradientPoint(GradientPoint point)
 {
     if (_gradientPoints.Contains(point))
     {
         throw new ArgumentException($"Cannont insert GradientPoint({point.Position}, {point.Color}) : Each GradientPoint is required to contain a unique position");
     }
     _gradientPoints.Add(point);
     _gradientPoints.Sort(delegate(GradientPoint p1, GradientPoint p2)
     {
         if (p1.Position > p2.Position)
         {
             return(1);
         }
         if (p1.Position < p2.Position)
         {
             return(-1);
         }
         return(0);
     });
 }