Module:Color contrast: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(replace html entity with # symbol - tested in /sandbox1 so as not to disturb /sandbox) |
(synced changes from sandbox - created an access point to lum available to other modules) |
||
Line 9: | Line 9: | ||
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) |
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) |
||
local function sRGB ( |
local function sRGB (v) |
||
if (v <= 0.03928) then |
if (v <= 0.03928) then |
||
v = v / 12.92 |
v = v / 12.92 |
||
Line 18: | Line 18: | ||
end |
end |
||
local function rgbdec2lum( |
local function rgbdec2lum(R, G, B) |
||
if ( 0 <= R and R < 256 and 0 <= G and G < 256 and 0 <= B and B < 256 ) then |
if ( 0 <= R and R < 256 and 0 <= G and G < 256 and 0 <= B and B < 256 ) then |
||
return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255) |
return 0.2126 * sRGB(R/255) + 0.7152 * sRGB(G/255) + 0.0722 * sRGB(B/255) |
||
Line 26: | Line 26: | ||
end |
end |
||
local function hsl2lum( |
local function hsl2lum(h, s, l) |
||
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then |
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then |
||
local c = (1 - math.abs(2*l - 1))*s |
local c = (1 - math.abs(2*l - 1))*s |
||
Line 58: | Line 58: | ||
end |
end |
||
-- This exports the function for use in other modules. |
|||
-- The colour is passed as a string. |
|||
function p._lum(color) |
|||
return color2lum(color) |
|||
end |
|||
local function color2lum(c) |
|||
if (c == nil) then |
if (c == nil) then |
||
Line 211: | Line 217: | ||
end |
end |
||
--[[ |
|||
Use {{#invoke:Color contrast|somecolor}} directly or |
|||
{{#invoke:Color contrast}} from a wrapper template. |
|||
Parameters: |
|||
-- |1= — required; A color to check. |
|||
--]] |
|||
function p.lum(frame) |
function p.lum(frame) |
||
local color = frame.args[1] or frame:getParent().args[1] |
|||
return p._lum(color) |
|||
end |
end |
||