📜  rgb 到 hex lua 代码示例

📅  最后修改于: 2022-03-11 14:54:56.047000             🧑  作者: Mango

代码示例1
-- assumes decimal values of r, g and b but can be easily retrofitted
function rgb_to_hex(r, g, b)
    --%02x: 0 means replace " "s with "0"s, 2 is width, x means hex
    return string.format("#%02x%02x%02x", 
        math.floor(r*255),
        math.floor(g*255),
        math.floor(b*255))
end

rgb_to_hex(0.01, 0.3, 0.1)
-- returns #024c19