-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generate icons from their glyph names
- Loading branch information
Showing
6 changed files
with
337 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.lua | ||
.luarocks | ||
/nerd-fonts/ | ||
/vim-colortemplate/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local M = {} | ||
|
||
---@param rrggbb string | ||
---@return string | ||
function M.darken(rrggbb) | ||
local light78 = 255 * 7 / 8 | ||
local light68 = 255 * 6 / 8 | ||
local light58 = 255 * 5 / 8 | ||
local light12 = 255 / 2 | ||
local light13 = 255 / 3 | ||
|
||
local hex = bit.tohex ---@type fun(n: number): string | ||
|
||
local r, g, b = rrggbb:match "%#(%x%x)(%x%x)(%x%x)" | ||
r, g, b = tonumber("0x" .. r), tonumber("0x" .. g), tonumber("0x" .. b) | ||
-- luminance formula: see https://stackoverflow.com/a/596243 | ||
local lum = 0.299 * r + 0.587 * g + 0.114 * b | ||
if lum < light13 then -------------------- darkest tertile | ||
return rrggbb | ||
elseif lum < light12 then ---------------- second darkest quartile | ||
r = hex(r / 4 * 3):sub(-2) | ||
g = hex(g / 4 * 3):sub(-2) | ||
b = hex(b / 4 * 3):sub(-2) | ||
elseif lum < light58 then ---------------- lightest octiles: first | ||
r = hex(r / 3 * 2):sub(-2) | ||
g = hex(g / 3 * 2):sub(-2) | ||
b = hex(b / 3 * 2):sub(-2) | ||
elseif lum < light68 then ---------------- lightest octiles: second | ||
r = hex(r / 2):sub(-2) | ||
g = hex(g / 2):sub(-2) | ||
b = hex(b / 2):sub(-2) | ||
elseif lum < light78 then ---------------- lightest octiles: third | ||
r = hex(r / 3):sub(-2) | ||
g = hex(g / 3):sub(-2) | ||
b = hex(b / 3):sub(-2) | ||
else ------------------------------------- lightest octile | ||
r = hex(r / 5):sub(-2) | ||
g = hex(g / 5):sub(-2) | ||
b = hex(b / 5):sub(-2) | ||
end | ||
return string.format("#%s%s%s", r, g, b) | ||
end | ||
|
||
return M |
Oops, something went wrong.