打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

RIA Wiki 已更新到 1.41!部分 CSS 在新版本下可能有不同的表现,请编辑者注意检查和修改。 目前wiki关闭了自行注册账号的功能,如需注册账号,请查阅Help:注册账号

模块:ColorHexToDec:修订间差异

来自RIA | Wiki
秋月白留言 | 贡献
创建页面,内容为“local p = {} -- 十六进制颜色转十进制RGB(完整版) function p.hexToDec(frame) local hex = frame.args[1] or "000000" -- 移除可能存在的#号 hex = hex:gsub("#", "") -- 如果是3位简写,扩展为6位 if hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then hex = hex:gsub("(.)(.)(.)", "%1%1%2%2%3%3") end -- 验证输入格式(6位十六进制) if not hex:match("^[0-9A-Fa-f][0-9A-Fa…”
 
秋月白留言 | 贡献
无编辑摘要
 
第1行: 第1行:
local p = {}
local p = {}


-- 十六进制颜色转十进制RGB(完整版)
function p.hexToDec(frame)
function p.hexToDec(frame)
     local hex = frame.args[1] or "000000"
     local hex = frame.args[1] or "000000"
      
      
    -- 移除可能存在的#号
     hex = hex:gsub("#", "")
     hex = hex:gsub("#", "")
      
      
    -- 如果是3位简写,扩展为6位
     if hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
     if hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
         hex = hex:gsub("(.)(.)(.)", "%1%1%2%2%3%3")
         hex = hex:gsub("(.)(.)(.)", "%1%1%2%2%3%3")
     end
     end
      
      
    -- 验证输入格式(6位十六进制)
     if not hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
     if not hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
         return "000,000,000" -- 返回默认黑色
         return "000,000,000"
     end
     end
      
      
    -- 提取RGB分量
     local r_hex = hex:sub(1, 2)
     local r_hex = hex:sub(1, 2)
     local g_hex = hex:sub(3, 4)
     local g_hex = hex:sub(3, 4)
     local b_hex = hex:sub(5, 6)
     local b_hex = hex:sub(5, 6)
      
      
    -- 转换为十进制
     local r_dec = tonumber(r_hex, 16) or 0
     local r_dec = tonumber(r_hex, 16) or 0
     local g_dec = tonumber(g_hex, 16) or 0
     local g_dec = tonumber(g_hex, 16) or 0
     local b_dec = tonumber(b_hex, 16) or 0
     local b_dec = tonumber(b_hex, 16) or 0
      
      
    -- 返回纯数字格式:rrr,ggg,bbb
     return string.format("%d,%d,%d", r_dec, g_dec, b_dec)
     return string.format("%d,%d,%d", r_dec, g_dec, b_dec)
end
end


return p
return p

2026年3月5日 (四) 10:33的最新版本

此模块的文档可以在模块:ColorHexToDec/doc创建

local p = {}

function p.hexToDec(frame)
    local hex = frame.args[1] or "000000"
    
    hex = hex:gsub("#", "")
    
    if hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
        hex = hex:gsub("(.)(.)(.)", "%1%1%2%2%3%3")
    end
    
    if not hex:match("^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$") then
        return "000,000,000"
    end
    
    local r_hex = hex:sub(1, 2)
    local g_hex = hex:sub(3, 4)
    local b_hex = hex:sub(5, 6)
    
    local r_dec = tonumber(r_hex, 16) or 0
    local g_dec = tonumber(g_hex, 16) or 0
    local b_dec = tonumber(b_hex, 16) or 0
    
    return string.format("%d,%d,%d", r_dec, g_dec, b_dec)
end

return p