从两个RGB值创建新颜色

时间:2014-12-15 08:17:31

标签: rgb livecode

是否可以合并两个RGB值以在livecode中创建另一种颜色?

示例:

First color: (0,0,255) //BLUE

Second color: (255,0,0) //RED

在这种情况下,我想将两种颜色的结果存储到变量中。

让我们说,put "0, 0, 255" + "255, 0, 0" into CombinedColors

2 个答案:

答案 0 :(得分:1)

使用RGB值组合2种颜色,有2种方法。

  1. 如果您需要更轻的纹理,您需要使用的公式是 (r1, g1, b1) + (r2, g2, b2) = (min(r1+r2, 255), min(g1+g2, 255), min(b1+b2, 255))

  2. 如果您需要稍暗的纹理,请使用 (r1, g1, b1) + (r2, g2, b2) = ((r1 + r2) / 2, (g1 + g2) / 2, (b1 + b2) / 2)

  3. 或者,如果您只是想避免麻烦,请使用这个简单的在线工具http://meyerweb.com/eric/tools/color-blend/

答案 1 :(得分:1)

目前尚不清楚如何组合颜色。如果你想混合颜色,你可以简单地添加它们。

put 255,0,0 into myRed
put 0,0,255 into myBlue
put 0,10,100 into myGreen
repeat with x = 1 to 3
  put min(item x of myRed + item x of myBlue + item x of myGreen,255) into \
    item x of myNewColor
end repeat

我在这里使用的公式没有多大意义。如果您可以在问题中更具体,我将能够使用更好的公式调整我的答案。

您也可以使用加权值:

put min(.333*item x of myRed + .333*item x of myBlue + .334*item \
        x of myGreen,255) into item x of myNewColor

您可以调整重量以使混合看起来更自然。 (此示例使用3种颜色来演示权重)。