看到这个问题 Calculate the color at a given point on a gradient between two colors? 我在这里引用了一个非常简单且有效的解决方案:
// You simply linearly interpolate the red, the green, and the blue channels like this:
resultRed = color1.red + percent * (color2.red - color1.red);
resultGreen = color1.green + percent * (color2.green - color1.green);
resultBlue = color1.blue + percent * (color2.blue - color1.blue);
// where percent is a value between 0 and 1 indicating the desired relative
// location between color1 and color2.
在原始问题的示例中,渐变从红色到蓝色,再到您通常预期的紫色。
现在,如果您想从红色变为蓝色围绕色轮的另一(更长)方式,通过橙色、黄色、绿色,您如何计算渐变点?