You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
6.6 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, May 12, 2018, 12:51 AM -->
<!-- MuClient version 5.06-pre -->
<!-- Plugin "Contrast_Picker" generated by Plugin Wizard -->
<muclient>
<plugin
name="Contrast_Picker"
author="Crowley"
id="977138a7afb5ab493795edb7"
language="Lua"
purpose="Checks contrast ratios to pick better contrasting colors."
save_state="y"
date_written="2018-05-12 00:48:25"
requires="4.80"
version="1.0"
>
</plugin>
<!-- Aliases -->
<aliases>
<alias
script="onCommand"
match="^contrast (.*?)(?:\s(.*?))?(?:\s(.*?))?$"
enabled="y"
group="ContrastChecker"
regexp="y"
send_to="12"
sequence="100"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
color_table = {
"pink",
"lightpink",
"hotpink",
"deeppink",
"palevioletred",
"mediumvioletred",
"lightsalmon",
"salmon",
"darksalmon",
"lightcoral",
"indianred",
"crimson",
"firebrick",
"darkred",
"red",
"orangered",
"tomato",
"coral",
"darkorange",
"orange",
"yellow",
"lightyellow",
"lemonchiffon",
"lightgoldenrodyellow",
"papayawhip",
"moccasin",
"peachpuff",
"palegoldenrod",
"khaki",
"darkkhaki",
"gold",
"cornsilk",
"blanchedalmond",
"bisque",
"navajowhite",
"wheat",
"burlywood",
"tan",
"rosybrown",
"sandybrown",
"goldenrod",
"darkgoldenrod",
"peru",
"chocolate",
"saddlebrown",
"sienna",
"brown",
"maroon",
"lavender",
"thistle",
"plum",
"violet",
"orchid",
"fuchsia",
"magenta",
"mediumorchid",
"mediumpurple",
"blueviolet",
"darkviolet",
"darkorchid",
"darkmagenta",
"purple",
"indigo",
"slateblue",
"darkslateblue",
"mediumslateblue",
"greenyellow",
"chartreuse",
"lawngreen",
"lime",
"limegreen",
"palegreen",
"lightgreen",
"mediumspringgreen",
"springgreen",
"mediumseagreen",
"seagreen",
"forestgreen",
"green",
"darkgreen",
"yellowgreen",
"olivedrab",
"olive",
"darkolivegreen",
"mediumaquamarine",
"darkseagreen",
"lightseagreen",
"darkcyan",
"teal",
"aqua",
"cyan",
"lightcyan",
"paleturquoise",
"aquamarine",
"turquoise",
"mediumturquoise",
"darkturquoise",
"cadetblue",
"steelblue",
"lightsteelblue",
"powderblue",
"lightblue",
"skyblue",
"lightskyblue",
"deepskyblue",
"dodgerblue",
"cornflowerblue",
"mediumslateblue",
"royalblue",
"blue",
"mediumblue",
"darkblue",
"navy",
"midnightblue",
"white",
"snow",
"honeydew",
"mintcream",
"azure",
"aliceblue",
"ghostwhite",
"whitesmoke",
"seashell",
"beige",
"oldlace",
"floralwhite",
"ivory",
"antiquewhite",
"linen",
"lavenderblush",
"mistyrose",
"gainsboro",
"lightgrey",
"silver",
"darkgray",
"gray",
"dimgray",
"lightslategray",
"slategray",
"darkslategray",
"black"
}
function lumRGB(s)
local red, green, blue, l = 0, 0, 0, 0
red = s%256
s = math.floor(s/256)
green = s%256
s = math.floor(s/256)
blue = s%256
red = lumForm(red)
green = lumForm(green)
blue = lumForm(blue)
l = (0.2126*red) + (0.7152*green) + (0.0722*blue)
return l
end
function lumForm(s)
local s = tonumber(s)
s = s/255
if s <= 0.03928 then
s = s/12.92
else
s = ((s+0.055)/1.055)^2.4
end
return s
end
function contrastCheck(a, b)
local a, b, s = tonumber(a), tonumber(b), 0
if a > b then
s = (a + 0.05)/(b + 0.05)
else
s = (b + 0.05)/(a + 0.05)
end
return s
end
function checkColor(s, b, e)
local max = 0
local b, e = tonumber(b), tonumber(e)
local ctable = {}
local sortcolors = {}
local l = lumRGB(ColourNameToRGB(s))
for _,v in ipairs(color_table) do
local ctrast = contrastCheck(l, lumRGB(ColourNameToRGB(v)))
if ctrast > 1 then
table.insert(ctable, {color = v, contrast = ctrast})
end
end
table.sort(ctable, function(a,b) return a.contrast > b.contrast end)
if b == "" or b == nil then b = 1 end
if e == "" or e == nil then e = 20 end
if e > #ctable then
if b > e then
b = 1
e = #ctable
else
e = #ctable
end
end
if b > e then
if e < 21 then
b = 1
else
b = e - 20
end
end
Note("Showing best matches for " .. s .. ":")
if #ctable > 0 then
for i = b,e do
ColourNote(s, ctable[i].color, i .. " - Sample text using " .. s .. " on " .. ctable[i].color .. " background. (" .. string.format("%.2f", ctable[i].contrast) .. ":1)")
end
else
ColourNote(s, "", "Sorry, " .. s .. " does not pair well with any background, except maybe black.")
end
end
function onCommand(name, line, arg)
if arg[1]:upper() == "HELP" then
onHelp()
else
checkColor(arg[1], arg[2], arg[3])
end
end
function onHelp()
Note("Contrast Generator Help:")
Note("contrast help - Brings up this help file")
Note("contrast <color> - Returns the top 20 contrast ratios")
Note("contrast <color> <num1> <num2> - Returns contrast ratios ranked num1 through num2")
Note("*<color> must be html color name (e.g. aliceblue, yellow, darkgreen, etc.)")
Note("")
Note("This plugin helps you decide the best contrasting colors by comparing")
Note("the luminance values and returning a ratio. Ratios are ranked from 1:1")
Note("to 21:1. The higher the ratio, the better the contrast, thus the better")
Note("your ability to read the text will be.")
end
function OnPluginInstall()
if not GetVariable("already_sent") then
onHelp()
SetVariable("already_sent", "true")
end
end
]]>
</script>
</muclient>