颜色范围Python

2024-06-02 07:02:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何根据介于[0-100]之间的值来获得颜色,其中0是红色,1是绿色,我希望它们之间的值是红色和绿色(橙色、黄色…,…)之间的插值颜色。我正在Blender 3D中使用python,下面的代码行可以生成彩虹色,如here所示,但我想知道如何将其设置为仅在红色、黄色和绿色之间,以及如何控制颜色范围(0-100)

import colorsys
(r, g, b) = colorsys.hsv_to_rgb(float(depth) / maxd, 1.0, 1.0)
R, G, B = int(255 * r), int(255 * g), int(255 * b)

Tags: to代码importhere颜色rgbhsvint