I am working on a program, that is able to generate landmasses and mountains with contour lines. I would like to distinguish each contour line with a separate shade of particular color, say:
- Green 0-15 (LowLands)
- WheatYellow 16-30 (MidLands)
- Brown 31-40 (HighLands)
- SnowWhite 41-50 (MountainTops)
I tried several attitudes, one of them is this piece of code I found on this website
public static Color[] GetColorShades(Color baseColor, int shadesCount)
{
shadesCount *= 2;
Color[] output = new Color[shadesCount];
for (int index = 0; index < shadesCount; index++)
{
output[index] = DarkenColor(baseColor, (double)index / (double)shadesCount);
}
return output;
}
private static Color DarkenColor(Color color, double fraction)
{
int red = (int)Math.Round(Math.Max(0, color.R - 255 * fraction));
int green = (int)Math.Round(Math.Max(0, color.G - 255 * fraction));
int blue = (int)Math.Round(Math.Max(0, color.B - 255 * fraction));
return Color.FromArgb(red, green, blue);
}
This code works fine for green color. but for some reason fails to generate color shades of yellow and brown. White also seems to be a problem.
Is anyone able to help me with an algorhitm that would split a number that defines height maximum to four groups, each with shades of a particular color? See image for inspiration
This is how it works with strictly defined hexadecimal color codes:
This is what I get when I apply algorithm above: