You need to look up colour models. There are various methods of describing a colour, RGB, HSV, And so on. All you do is to have the coordinates of the start and end colours, divide the distance between the two into any number of steps, but the same for each axis, and then increment each axis to get your fade.
With some colour have a colour either side of the grey line, and if you do it fades through that, otherwise there is always a path between two colours.