private static IEnumerable <HsvColor> InterpolateLinearly(IList <HsvColor> colors, int maxIterationDepth) { int interpolationCount = COLOR_INTERPOLATION_FACTOR * maxIterationDepth; double intervalWidth = (double)interpolationCount / (colors.Count - 1); for (int i = 0; i < interpolationCount; i++) { int colorIndex = (int)Math.Floor(i / intervalWidth); HsvColor color1 = colors[colorIndex]; HsvColor color2 = colors[colorIndex + 1]; double interpolationDegree = i / intervalWidth - colorIndex; yield return(color1.InterpolateLinearly(color2, interpolationDegree)); } }