【问题标题】:Determining the RYB complement of a color确定颜色的 RYB 补色
【发布时间】:2019-06-13 04:23:27
【问题描述】:

我试图在 RYB 空间中获得颜色的颜色和谐。我已成功实现 RGB 和声,但无法让 RYB 和声正常工作。他们离 FAR 远了。

我的程序获取 HEX/HTML 颜色,将其转换为 RGB,将 RGB 转换为 RYB,将 RYB 转换为 HSL,并通过增加色调从那里执行和声计算。我使用https://www.rapidtables.com/convert/color/rgb-to-hsl.html 上的公式将 RYB 转换为 HSL。在该页面上,它给出了将 RGB 转换为 HSL 的公式。我只是使用 RYB 值代替 RGB。下面是我用来将 RGB 转换为 RYB 的公式:

var r = color[0], g = color[1], b = color[2];

// Remove the whiteness from the color.

var w = Math.min(r, g, b);

r -= w;

g -= w;

b -= w;



var mg = Math.max(r, g, b);



// Get the yellow out of the red+green.

var y = Math.min(r, g);

r -= y;

g -= y;



// If this unfortunate conversion combines blue and green, then cut each in

// half to preserve the value's maximum range.

if (b && g) {

    b /= 2.0;

    g /= 2.0;

}



// Redistribute the remaining green.

y += g;

b += g;



// Normalize to values.

var my = Math.max(r, y, b);

if (my) {

    var n = mg / my;

    r *= n;

    y *= n;

    b *= n;

}



// Add the white back in.

r += w;

y += w;

b += w;



// And return back the ryb typed accordingly.

return [r, y, b];

}

在红黄蓝中得到红色的补色时,应该是绿色。得到RGB中红色的补色时,应该是青色。无论如何,我的程序都会给出青色。 该程序应该给我这个:http://prntscr.com/o16ava 相反,它给了我:http://prntscr.com/o16b08

【问题讨论】:

标签: math colors interpolation rgb color-wheel


【解决方案1】:

它无法正常工作,因为正如您在 cmets 中提到的,当您将 ryb 转换为 hsl 时,您将它视为 rgb。

当您使用以下值运行上面发布的代码时:red = 255, green = 0, blue = 0

它返回值:红色 = 255,黄色 = 0,蓝色 = 0

恭维:红色 = 0,黄色 = 255,蓝色 = 255

如果您将其传递给旨在将 rgb 转换为 hsl 的函数,它会像您告诉它转换一样计算它:red = 0, green = 255, blue = 255

这是青色。

您需要从 ryb 转换回 rgb 或获取一个旨在将 ryb 转换为 hsl 的函数。

【讨论】:

  • 谢谢!!我想知道您是否可能知道有关将 RYB 转换为 HSL 的任何资源?
  • 我不知道有什么方法可以直接做。我可能会选择 RYB->RGB->HSL。
  • 是的!因此,我阅读了更多关于此的内容并遇到了stackoverflow.com/questions/14095849/…,它为我提供了从 ryb 到 rgb 的公式。
猜你喜欢
  • 2012-12-04
  • 2020-01-16
  • 2011-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
相关资源
最近更新 更多