dev (formatter): formatted with StyLua utils/

dev-doc
Pocco81 3 years ago
parent 685a90ad9a
commit 69ef80d89d

@ -11,7 +11,7 @@ local function color_is_bright(r, g, b)
end
function M.hex2rgb(hex)
return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
return tonumber("0x" .. hex:sub(1, 2)), tonumber("0x" .. hex:sub(3, 4)), tonumber("0x" .. hex:sub(5, 6))
end
function M.assert_brightness(color)
@ -20,7 +20,7 @@ function M.assert_brightness(color)
local g = M.hex2rgb(string.sub(hex, 3, 4))
local b = M.hex2rgb(string.sub(hex, 5, 6))
if (color_is_bright(tonumber(r), tonumber(g), tonumber(b)) == true) then
if color_is_bright(tonumber(r), tonumber(g), tonumber(b)) == true then
return true -- bright
end

@ -50,7 +50,7 @@ hsluv.get_bounds = function(l)
local top1 = (284517 * m1 - 94839 * m3) * sub2
local top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * l * sub2 - 769860 * t * l
local bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t
table.insert(result, {slope = top1 / bottom, intercept = top2 / bottom})
table.insert(result, { slope = top1 / bottom, intercept = top2 / bottom })
end
end
return result
@ -112,16 +112,16 @@ hsluv.xyz_to_rgb = function(tuple)
return {
hsluv.from_linear(hsluv.dot_product(hsluv.m[1], tuple)),
hsluv.from_linear(hsluv.dot_product(hsluv.m[2], tuple)),
hsluv.from_linear(hsluv.dot_product(hsluv.m[3], tuple))
hsluv.from_linear(hsluv.dot_product(hsluv.m[3], tuple)),
}
end
hsluv.rgb_to_xyz = function(tuple)
local rgbl = {hsluv.to_linear(tuple[1]), hsluv.to_linear(tuple[2]), hsluv.to_linear(tuple[3])}
local rgbl = { hsluv.to_linear(tuple[1]), hsluv.to_linear(tuple[2]), hsluv.to_linear(tuple[3]) }
return {
hsluv.dot_product(hsluv.minv[1], rgbl),
hsluv.dot_product(hsluv.minv[2], rgbl),
hsluv.dot_product(hsluv.minv[3], rgbl)
hsluv.dot_product(hsluv.minv[3], rgbl),
}
end
@ -156,9 +156,9 @@ hsluv.xyz_to_luv = function(tuple)
end
local L = hsluv.y_to_l(Y)
if L == 0 then
return {0, 0, 0}
return { 0, 0, 0 }
end
return {L, 13 * L * (varU - hsluv.refU), 13 * L * (varV - hsluv.refV)}
return { L, 13 * L * (varU - hsluv.refU), 13 * L * (varV - hsluv.refV) }
end
hsluv.luv_to_xyz = function(tuple)
@ -166,13 +166,13 @@ hsluv.luv_to_xyz = function(tuple)
local U = tuple[2]
local V = tuple[3]
if L == 0 then
return {0, 0, 0}
return { 0, 0, 0 }
end
local varU = U / (13 * L) + hsluv.refU
local varV = V / (13 * L) + hsluv.refV
local Y = hsluv.l_to_y(L)
local X = 0 - (9 * Y * varU) / (((varU - 4) * varV) - varU * varV)
return {X, Y, (9 * Y - 15 * varV * Y - varV * X) / (3 * varV)}
return { X, Y, (9 * Y - 15 * varV * Y - varV * X) / (3 * varV) }
end
hsluv.luv_to_lch = function(tuple)
@ -189,14 +189,14 @@ hsluv.luv_to_lch = function(tuple)
H = 360 + H
end
end
return {L, C, H}
return { L, C, H }
end
hsluv.lch_to_luv = function(tuple)
local L = tuple[1]
local C = tuple[2]
local Hrad = tuple[3] / 360.0 * 2 * math.pi
return {L, math.cos(Hrad) * C, math.sin(Hrad) * C}
return { L, math.cos(Hrad) * C, math.sin(Hrad) * C }
end
hsluv.hsluv_to_lch = function(tuple)
@ -204,12 +204,12 @@ hsluv.hsluv_to_lch = function(tuple)
local S = tuple[2]
local L = tuple[3]
if L > 99.9999999 then
return {100, 0, H}
return { 100, 0, H }
end
if L < 0.00000001 then
return {0, 0, H}
return { 0, 0, H }
end
return {L, hsluv.max_safe_chroma_for_lh(L, H) / 100 * S, H}
return { L, hsluv.max_safe_chroma_for_lh(L, H) / 100 * S, H }
end
hsluv.lch_to_hsluv = function(tuple)
@ -218,13 +218,13 @@ hsluv.lch_to_hsluv = function(tuple)
local H = tuple[3]
local max_chroma = hsluv.max_safe_chroma_for_lh(L, H)
if L > 99.9999999 then
return {H, 0, 100}
return { H, 0, 100 }
end
if L < 0.00000001 then
return {H, 0, 0}
return { H, 0, 0 }
end
return {H, C / max_chroma * 100, L}
return { H, C / max_chroma * 100, L }
end
hsluv.hpluv_to_lch = function(tuple)
@ -232,12 +232,12 @@ hsluv.hpluv_to_lch = function(tuple)
local S = tuple[2]
local L = tuple[3]
if L > 99.9999999 then
return {100, 0, H}
return { 100, 0, H }
end
if L < 0.00000001 then
return {0, 0, H}
return { 0, 0, H }
end
return {L, hsluv.max_safe_chroma_for_l(L) / 100 * S, H}
return { L, hsluv.max_safe_chroma_for_l(L) / 100 * S, H }
end
hsluv.lch_to_hpluv = function(tuple)
@ -245,12 +245,12 @@ hsluv.lch_to_hpluv = function(tuple)
local C = tuple[2]
local H = tuple[3]
if L > 99.9999999 then
return {H, 0, 100}
return { H, 0, 100 }
end
if L < 0.00000001 then
return {H, 0, 0}
return { H, 0, 0 }
end
return {H, C / hsluv.max_safe_chroma_for_l(L) * 100, L}
return { H, C / hsluv.max_safe_chroma_for_l(L) * 100, L }
end
hsluv.rgb_to_hex = function(tuple)
@ -320,14 +320,14 @@ hsluv.hex_to_hpluv = function(s)
end
hsluv.m = {
{3.240969941904521, -1.537383177570093, -0.498610760293},
{-0.96924363628087, 1.87596750150772, 0.041555057407175},
{0.055630079696993, -0.20397695888897, 1.056971514242878}
{ 3.240969941904521, -1.537383177570093, -0.498610760293 },
{ -0.96924363628087, 1.87596750150772, 0.041555057407175 },
{ 0.055630079696993, -0.20397695888897, 1.056971514242878 },
}
hsluv.minv = {
{0.41239079926595, 0.35758433938387, 0.18048078840183},
{0.21263900587151, 0.71516867876775, 0.072192315360733},
{0.019330818715591, 0.11919477979462, 0.95053215224966}
{ 0.41239079926595, 0.35758433938387, 0.18048078840183 },
{ 0.21263900587151, 0.71516867876775, 0.072192315360733 },
{ 0.019330818715591, 0.11919477979462, 0.95053215224966 },
}
hsluv.refY = 1.0
hsluv.refU = 0.19783000664283

@ -18,7 +18,7 @@ local hex_to_rgb = function(hex_str)
assert(string.find(hex_str, pat) ~= nil, "hex_to_rgb: invalid hex_str: " .. tostring(hex_str))
local red, green, blue = string.match(hex_str, pat)
return {tonumber(red, 16), tonumber(green, 16), tonumber(blue, 16)}
return { tonumber(red, 16), tonumber(green, 16), tonumber(blue, 16) }
end
---@param fg string foreground color
@ -78,7 +78,7 @@ function util.string_to_color(colors, value, default)
return value
end
local acceptable_colors = {"black", "red", "green", "blue", "magenta", "cyan", "white", "orange", "pink"}
local acceptable_colors = { "black", "red", "green", "blue", "magenta", "cyan", "white", "orange", "pink" }
for _, ac in ipairs(acceptable_colors) do
if string.match(value, ac) then
return colors[value]
@ -104,7 +104,7 @@ end
function util.syntax(tbl)
for group, colors in pairs(tbl) do
if (type(group) == "number") then
if type(group) == "number" then
for inner_group, clrs in pairs(colors) do
util.highlight(inner_group, clrs)
end

Loading…
Cancel
Save