둘러보기 메뉴
검색
바뀐글
임의글
개인 도구
가입하기
로그인
도움말
도움말
질문게시판
자주 묻는 질문
커뮤니티
실시간 채팅방
가입인사게시판
자유게시판
뉴스게시판
제재안게시판
최근 토론
페미위키
공지사항
개선 요청
바뀐글
임의글
파일 올리기
다면 분류 목록
특수 문서 목록
모듈:사용자:Darkbosal/HSV 문서 원본 보기
이름공간
모듈
토론
주시
도구
여기를 가리키는 문서
가리키는 글의 최근 바뀜
문서 정보
위키베이스 항목
행위
보기
읽기
원본 보기
역사 보기
←
모듈:사용자:Darkbosal/HSV
문서 편집 권한이 없습니다. 다음 이유를 확인해주세요.
요청한 명령은 다음 중 하나의 권한을 가진 사용자에게 제한됩니다:
사용자
,
Seeders
.
문서를 고치려면 이메일 인증 절차가 필요합니다.
사용자 환경 설정
에서 이메일 주소를 입력하고 이메일 주소 인증을 해주시기 바랍니다.
문서의 원본을 보거나 복사할 수 있습니다.
local p = {} function rgb2hsv(r, g, b) local max = math.max(r, g, b) local min = math.min(r, g, b) local c = max - min -- calculate hue local h if c == 0 then h = 0 elseif max == r then h = 60 * (0 + ((g - b)/c)) elseif max == g then h = 60 * (2 + ((b - r)/c)) elseif max == b then h = 60 * (4 + ((r - g)/c)) end if h < 0 then h = h + 360 end -- calculate value local v = max -- calculate luminance -- local l = (max + min) / 2 -- calculate saturation local s if c == 0 then s = 0 else s = c/v end return h, s, v end function hsv2rgb(h, s, v) local hi = math.floor(h / 60) local f = ((h / 60) - hi) local p = v * (1 - s) local q = v * (1 - s * f) local t = v * (1 - s * (1 - f)) if hi == 1 then return q, v, p elseif hi == 2 then return p, v, t elseif hi == 3 then return p, q, v elseif hi == 4 then return t, p, v elseif hi == 5 then return v, p, q else return v, t, p end end function decodeRGBHex(rgb) local r = string.sub(rgb, 1, 2) local g = string.sub(rgb, 3, 4) local b = string.sub(rgb, 5, 6) return tonumber(r, 16), tonumber(g, 16), tonumber(b, 16) end function getRGB(args) local r, g, b, i if string.len(args[1]) == 6 then r, g, b = decodeRGBHex(args[1]) i = 2 else r = args[1] g = args[2] b = args[3] i = 4 end return r / 255, g / 255, b / 255, i end --[[toHSV Description: Converts a RGB color to a HSV color. Usage: {{#invoke:HSV|toHSV|R|G|B}} or {{#invoke:HSV|toHSV|RGBhex}} Output: hue [0°..360°]/saturation [0..1]/value [0..1] ]] function p.toHSV(frame) local r, g, b = getRGB(frame.args) local h, s, v = rgb2hsv(r, g, b) return h .. "/" .. s .. "/" .. v end --[[hue Description: Returns the hue of a RGB color. Usage: {{#invoke:HSV|hue|R|G|B}} or {{#invoke:HSV|hue|RGBhex}} Output: hue [0°..360°] ]] function p.hue(frame) local r, g, b = getRGB(frame.args) local h, s, v = rgb2hsv(r, g, b) return h end --[[saturation Description: Returns the saturation of a RGB color. Usage: {{#invoke:HSV|saturation|R|G|B}} or {{#invoke:HSV|saturation|RGBhex}} Output: saturation [0..1] ]] function p.saturation(frame) local r, g, b = getRGB(frame.args) local h, s, v = rgb2hsv(r, g, b) return s end --[[value Description: Returns the hue of a RGB color. Usage: {{#invoke:HSV|value|R|G|B}} or {{#invoke:HSV|value|RGBhex}} Output: value [0..1] ]] function p.value(frame) local r, g, b = getRGB(frame.args) local h, s, v = rgb2hsv(r, g, b) return v end --[[saturate Description: Saturates a RGB color by a given factor. Usage: {{#invoke:HSV|saturate|R|G|B|factor}} or {{#invoke:HSV|saturate|RGBhex|factor}} Optionally "factor" can be followed by another parameter with the value "hex" can be given to return the RGB color in a hexadecimal representation. Output: saturated RGB ]] function p.saturate(frame) local r, g, b, i = getRGB(frame.args) -- convert to HSV local h, s, v = rgb2hsv(r, g, b) -- saturate s = s * frame.args[i] if s < 0 then s = 0 elseif s > 1 then s = 1 end -- convert back to RGB local r, g, b = hsv2rgb(h, s, v) r = math.floor(r * 255 + 0.5) g = math.floor(g * 255 + 0.5) b = math.floor(b * 255 + 0.5) -- return values if frame.args[i + 1] == "hex" then return string.format("%.2X%.2X%.2X", r, g, b) else return r .. "/" .. g .. "/" .. b end end --[[toRGB Description: Converts a HSV color to a RGB color. Usage: {{#invoke:HSV|toRGB|H|S|V}} with H in [0°..360°], S in [0..1] and V in [0..1]. Optionally a 4th parameter with the value "hex" can be given to return the RGB color in a hexadecimal representation. Output: R/G/B ]] function p.toRGB(frame) local r, g, b = hsv2rgb(frame.args[1], frame.args[2], frame.args[3]) -- transform from real [0..1] to integer [0..255] r = math.floor(r * 255 + 0.5) g = math.floor(g * 255 + 0.5) b = math.floor(b * 255 + 0.5) -- return values if frame.args[4] == "hex" then return string.format("%.2X%.2X%.2X", r, g, b) else return r .. "/" .. g .. "/" .. b end end return p
이 문서에서 사용한 틀:
모듈:사용자:Darkbosal/HSV/설명문서
(
원본 보기
)
모듈:사용자:Darkbosal/HSV
문서로 돌아갑니다.
다른 언어