我正在尝试编写一个函数来计算给定前景和背景颜色的软光。职能如下;
var background = '0xFFFFFF';
var foreground = '0x47768C';
var calculateSoftlight = function (background, foreground) {
var intBackground = parseInt(background, 16);
var intForeground = parseInt(foreground, 16);
var softlight = (1 - (2 * intForeground)) * (intBackground*intBackground) + (2 * intForeground * intBackground);
return softlight.toString(16);
}
calculateSoftlight(background, foreground); //-8eed155338bb200000 我正在使用这里列出的Pegtop公式;modes。我不确定这一做法是否正确。有什么想法吗?
发布于 2014-10-31 23:49:39
将公式应用于每个RGB值,而不是使用十六进制。如果需要使用十六进制作为输入,则可能需要进行转换。
您需要规范每个值(所以是value / 255),并在公式中使用它。然后将结果乘以255,然后将其转换为8位值。
像这样的东西应该是接近的,我没有特别地使用这个公式,所以这是未经测试的。
var top = top / 255,
bot = bot / 255;
top = ((1 - 2*bot)*Math.pow(top, 2)) + 2*bot*top,
top = Math.round(top * 255);https://stackoverflow.com/questions/26684908
复制相似问题