【发布时间】: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
【问题讨论】:
-
在显示之前如何将 ryb 转换回 rgb?
-
问题是我没有将 RYB 转换回 RGB。我将 HSL 转换回 RGB 以将其显示在屏幕上。我的程序从 HEX/HTML 代码 ---> RGB 255 ---> RYB 255 ---> HSL ---> RGB 使用 rapidtables.com/convert/color/hsl-to-rgb.html
-
那么 RYB 到 HSL 的步骤怎么做?
-
我在这些公式中使用 RYB 代替 RGB rapidtables.com/convert/color/rgb-to-hsl.html
标签: math colors interpolation rgb color-wheel