首页 > 解决方案 > 如何在没有 ProcessingJS 的情况下制作 lerpColor() 函数

问题描述

我想创建自己的lerpColor(c1, c2, amount)函数,其输出与 ProcessingJS http://processingjs.org/reference/lerpColor_/

我正在寻找或类似的东西:

lerpColor = function (c1, c2, amount) {
    // Do some math stuff here
    return(newColor);
};

任何帮助将不胜感激。

标签: functionmathcolorsprocessing.jslerp

解决方案


如果此颜色插值纯粹在 RGB 颜色空间中工作,则需要提取颜色分量并将下一个算法应用于每个分量

r1 = red(c1)
r2 = red(c2)
result_red = (1-amount) * r1  + amount * r2
or 
result_red = r1 + amount * (r2 - r1)
...
return(color(result_red, result_green, result_blue));

推荐阅读