2

I know this is very similar to a previous question that I had posted, I cannot figure out how to modify it to suit this problem.

I have a array of values between 0 and 1. I want to convert these values to RGB color array ranging from red (0) to blue (1). The solution suggested in the previous question converted values to HSV tuples first, and then used colosys.hsv_to_rgb() to convert to RGB values.

This was fine if I wanted to generate colors between red and green. I could interpolate the hue value linearly. However, when the extreme colors are red and blue, the intermediary values take on green color because green hue lies between red and blue. Is there a way I can avoid this and get colors only in the vicinity of red and blue?

I know I can linearly interpolate RGB values directly, but that does not give a good color spectrum. So please tell me a solution using HSV space.

4

2 回答 2

4

将您的 0-1 输入缩放为 0-(-120) 输出,将模数乘以 360,并将其用作您的色调(或 0-(-0.3333...) 和 1.0 视情况而定)。

于 2012-09-14T21:51:06.680 回答
3

色调是一个循环值,因此,如果将总色调范围添加到任何颜色的色调(模其最大值,使其仍在范围内),您将获得完全相同的颜色。因此,与其从红色增加到蓝色,不如将其从红色减少到蓝色。HSV 是一种圆柱形颜色模型。

在此处输入图像描述

于 2012-09-14T21:56:02.033 回答