3种颜色之间的颜色插值 [英] Color interpolation between 3 colors
本文介绍了3种颜色之间的颜色插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的公式得到一个漂亮的颜色渐变从colorA到colorB,但我不知道如何做同样的3种颜色,所以渐变从colorA到colorB到colorC
I use the following equation to get a nice color gradient from colorA to colorB, but I have no idea how to do the same for 3 colors, so the gradient goes from colorA to colorB to colorC
colorT = colorA * p + colorB *(1.0 - p);
其中p是从0.0到1.0的百分比
colorT = colorA * p + colorB * (1.0 - p);
where "p" is the a percentage from 0.0 to 1.0
感谢
推荐答案
p = 0.0到2.0:
Well, for 3 colors, you can just to the same with p = 0.0 to 2.0:
if p <= 1.0
colorT = colorA * p + colorB * (1.0 - p);
else
colorT = colorB * (p - 1.0) + colorC * (2.0 - p);
或缩放,以便仍然可以使用p = 0.0至1.0:
Or scale it so you can still use p = 0.0 to 1.0:
if p <= 0.5
colorT = colorA * p * 2.0 + colorB * (0.5 - p) * 2.0;
else
colorT = colorB * (p - 0.5) * 2.0 + colorC * (1.0 - p) * 2.0;
这篇关于3种颜色之间的颜色插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文