I have the following list of 10 colors:
public static readonly IList<Brush> lineColors = new ReadOnlyCollection<Brush>
(new List<Brush> {
new SolidColorBrush(Color.FromRgb(35, 31, 32)),
new SolidColorBrush(Color.FromRgb(64, 64, 66)),
new SolidColorBrush(Color.FromRgb(89, 89, 91)),
new SolidColorBrush(Color.FromRgb(110, 111, 113)),
new SolidColorBrush(Color.FromRgb(129, 130, 132)),
new SolidColorBrush(Color.FromRgb(148, 149, 153)),
new SolidColorBrush(Color.FromRgb(168, 169, 173)),
new SolidColorBrush(Color.FromRgb(189, 190, 193)),
new SolidColorBrush(Color.FromRgb(210, 211, 213)),
new SolidColorBrush(Color.FromRgb(231, 231, 232))
});
Now I also have a range from 1 to n. I'd like to map these value equally to this 10 colors so that the smallest value is the first color and the highest value is mapped to the last color. All the other colors should cover an equal distance in the value range.
How to do that?
I think this will maybe do it:
int position = Math.floor( value / ((max - min) / lineColors.Count));
lineColors.ElementAt(position);
But I'm not sure if this is valid for all possibilities and if there isn't a simpler solution.