[英]R or python, gradient of colors ranging from color1 to color2
我试图在不同的显微镜色调上对材料上的化学反应进行分类。 我的比例尺两端都有参考 colors,它们在所有扩展中都是同质的,所以基本上我只有 RGB 代码作为启动器。 颜色 1 是白色和 2 红色,所以我必须在白色和红色调之间移动,仅此而已。
我已经读过 colorrampPalette 可能在 R 中很有用,但它适用于预制的 colors,我只是这方面的新手,我尝试研究,但没有什么适合我想要的,你有什么推荐我? 谢谢
ps 也可以与 Python 一起使用
不知道有没有这样的function,不过写一个还是蛮容易的:
def gradients(color1, color2, steps):
# colors are tuples of ints representing RGB values
r1, g1, b1 = color1 # break color into separate values
r2, g2, b2 = color2
step_r = (r2 - r1) / steps # given n-steps, define step size for each color change
step_g = (g2 - g1) / steps
step_b = (b2 - b1) / steps
return [(int(r1 + step_r * i), # produce list of color applying respective step size over each iteration
int(g1 + step_g * i),
int(b1 + step_b * i)) for i in range(steps)]
结果:
>>> gradients((0,0,0), (255, 255, 255), 3)
>>> [(0, 0, 0), (85, 85, 85), (170, 170, 170)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.