이 모듈에 대한 설명문서는 모듈:AdjustBrightness/설명문서에서 만들 수 있습니다
local p = {}
local function hex_to_rgb(hex)
hex = hex:gsub("#", "")
if #hex ~= 6 then
return nil, nil, nil -- 잘못된 헥스 코드 처리
end
local r = tonumber(hex:sub(1, 2), 16)
local g = tonumber(hex:sub(3, 4), 16)
local b = tonumber(hex:sub(5, 6), 16)
return r, g, b
end
local function rgb_to_hex(r, g, b)
return string.format("#%02X%02X%02X", math.floor(r), math.floor(g), math.floor(b))
end
local function adjust_brightness(r, g, b, factor)
r = math.min(255, math.max(0, r * factor))
g = math.min(255, math.max(0, g * factor))
b = math.min(255, math.max(0, b * factor))
return r, g, b
end
function p.adjust(frame)
local hex = frame.args[1] or "#808080"
local direction = frame.args[2] or "brighten"
local percentage = tonumber(frame.args[3]:gsub("%%", ""))
if not percentage then
return "퍼센트값이 올바르지 않습니다. 숫자로 입력하세요 (예: 50%)."
end
if percentage < 0 or percentage > 100 then
return "퍼센트는 0%에서 100% 사이여야 합니다."
end
local factor = 1 + (percentage / 100)
if direction == "darken" then
factor = 1 - (percentage / 100)
elseif direction ~= "brighten" then
return "방향은 'brighten' 또는 'darken'만 가능합니다."
end
local r, g, b = hex_to_rgb(hex)
if not r or not g or not b then
return "유효하지 않은 헥스 코드입니다."
end
r, g, b = adjust_brightness(r, g, b, factor)
return rgb_to_hex(r, g, b)
end
return p