【发布时间】:2011-12-06 05:21:22
【问题描述】:
如何获取 r,g,b 值并将它们与网络安全调色板进行比较以找到 r,g,b 值的最佳匹配?
有这个: What is the best algorithm for finding the closest color in an array to another color?
但我不认为这是我需要的。我只需要将 r,g,b 与网络安全颜色进行比较,然后确定网络安全颜色是否是最佳选择。
Edit1:已删除
编辑2: 这是我到目前为止所拥有的。
local r, g, b = HSV2RGB(h, s, v)
local dither = copy(WEB_SAFE)
local lmod
for i, v in ipairs(dither) do
local r2, g2, b2 = Color2RGBA(v)
local hh, ss, vv = RGB2HSV(r2, g2, b2)
local a = hh - h
local b = ss - s
local c = vv - v
local mod = a*a + b*b + c*c
if not lmod or mod < lmod then
lmod = mod
r, g, b = r2, g2,b2
end
end
texture:SetBackgroundColor(r, g, b)
编辑 3: 这是它应该看起来的样子吗?
h=1 到 360,步长 5 pt,s=1 到 100,v = 89
【问题讨论】:
-
这正是您所需要的。只需将所有网络安全颜色放入一个数组中,将您的颜色与数组中的每种颜色一一比较,然后取差异最小的颜色。如果您愿意,我可以发布示例代码。
-
是否需要取每个 r,g,b 值或 h,s,v 或 32 位数字的差值?
-
这在我看来像 Lua 代码,所以我将其标记为这样。
-
我很高兴你得到了答案,但我真的很好奇:为什么在 2011 年需要网络安全颜色?现在你不能依赖至少 16 位的一切吗?
标签: colors lua color-palette web-safe-colors