Example #1
0
        /// <summary>
        /// Returns the color in this color range at the specified parameter.
        /// </summary>
        /// <param name="colorRange"></param>
        /// <param name="parameter">A value between 0.0 and 1.0.</param>
        /// <returns>A Color.</returns>
        public static Color GetColorAtParameter(ColorRange1D colorRange, double parameter = 0.0)
        {
            // If the supplied index matches one of the indexed colors' indices,
            // then just return that color.
            var found = colorRange.indexedColors.FirstOrDefault(ci => ci.Parameter == parameter);

            if (found != null)
            {
                return(found.Color);
            }

            if (colorRange.indexedColors.Count == 1)
            {
                return(colorRange.indexedColors.First().Color);
            }

            Color.IndexedColor1D c1, c2;

            c1 = colorRange.indexedColors.First();
            c2 = colorRange.indexedColors.Last();

            // Find the leading and trailing indexed color
            // between which we will linearly interpolate.
            foreach (var ci in colorRange.indexedColors)
            {
                if (ci.Parameter > c1.Parameter && ci.Parameter < parameter)
                {
                    c1 = ci;
                }

                if (ci.Parameter > parameter && ci.Parameter < c2.Parameter)
                {
                    c2 = ci;
                }
            }

            return(Color.Lerp(c1.Color, c2.Color, (parameter - c1.Parameter) / (c2.Parameter - c1.Parameter)));
        }
Example #2
0
        public static Color BuildColorFrom1DRange(List <Color> colors, List <double> parameters, double parameter)
        {
            var colorRange = ColorRange1D.ByColorsAndParameters(colors, parameters);

            return(ColorRange1D.GetColorAtParameter(colorRange, parameter));
        }
Example #3
0
        /// <summary>
        /// Returns the color in this color range at the specified parameter.
        /// </summary>
        /// <param name="colorRange"></param>
        /// <param name="parameter">A value between 0.0 and 1.0.</param>
        /// <returns>A Color.</returns>
        public static Color GetColorAtParameter(ColorRange1D colorRange, double parameter = 0.0)
        {
            // If the supplied index matches one of the indexed colors' indices,
            // then just return that color.
            var found = colorRange.indexedColors.FirstOrDefault(ci => ci.Parameter == parameter);
            if (found != null)
            {
                return found.Color;
            }

            if (colorRange.indexedColors.Count == 1)
            {
                return colorRange.indexedColors.First().Color;
            }

            Color.IndexedColor1D c1, c2;

            c1 = colorRange.indexedColors.First();
            c2 = colorRange.indexedColors.Last();

            // Find the leading and trailing indexed color
            // between which we will linearly interpolate.
            foreach (var ci in colorRange.indexedColors)
            {
                if (ci.Parameter > c1.Parameter && ci.Parameter < parameter)
                {
                    c1 = ci;
                }

                if (ci.Parameter > parameter && ci.Parameter < c2.Parameter)
                {
                    c2 = ci;
                }
            }

            return Color.Lerp(c1.Color, c2.Color, (parameter - c1.Parameter) / (c2.Parameter - c1.Parameter));
        }