diff --git a/lua/colors/doom-one/init.lua b/lua/colors/doom-one/init.lua index 1215506..4b9801e 100644 --- a/lua/colors/doom-one/init.lua +++ b/lua/colors/doom-one/init.lua @@ -7,7 +7,7 @@ -- Helpers {{{ -require('colors.utils') +local utils = require('colors.utils') -- }}} @@ -88,7 +88,7 @@ local yellow = '#ECBE7B' local blue = '#51afef' local dark_blue = '#2257A0' local magenta = '#c678dd' -local light_magenta = Lighten(magenta, 0.4) +local light_magenta = utils.Lighten(magenta, 0.4) local violet = '#a9a1e1' local cyan = '#46D9FF' local white = '#efefef' @@ -102,23 +102,23 @@ local bg_highlighted = '#4A4A45' local fg = '#bbc2cf' local fg_alt = '#5B6268' -local fg_highlight = Lighten(fg, 0.2) +local fg_highlight = utils.Lighten(fg, 0.2) -local tag = Mix(blue, cyan, 0.5) +local tag = utils.Mix(blue, cyan, 0.5) local diff_info_fg = orange -local diff_info_bg0 = Mix('#D8EEFD', bg, 0.6) -local diff_info_bg1 = Mix('#D8EEFD', bg, 0.8) +local diff_info_bg0 = utils.Mix('#D8EEFD', bg, 0.6) +local diff_info_bg1 = utils.Mix('#D8EEFD', bg, 0.8) local diff_add_fg = green -local diff_add_fg0 = Mix(green, fg, 0.4) -local diff_add_bg0 = Mix('#506d5b', bg, 0.6) -local diff_add_bg1 = Mix('#acf2bd', bg, 0.8) +local diff_add_fg0 = utils.Mix(green, fg, 0.4) +local diff_add_bg0 = utils.Mix('#506d5b', bg, 0.6) +local diff_add_bg1 = utils.Mix('#acf2bd', bg, 0.8) local gh_danger_fg = red -local gh_danger_fg0 = Mix(red, fg, 0.6) -local gh_danger_bg0 = Mix('#ffdce0', bg, 0.6) -local gh_danger_bg1 = Mix('#ffdce0', bg, 0.8) +local gh_danger_fg0 = utils.Mix(red, fg, 0.6) +local gh_danger_bg0 = utils.Mix('#ffdce0', bg, 0.6) +local gh_danger_bg1 = utils.Mix('#ffdce0', bg, 0.8) if current_bg == 'light' then light_bg = true @@ -142,36 +142,36 @@ if current_bg == 'light' then blue = '#4078f2' dark_blue = '#a0bcf8' magenta = '#a626a4' - light_magenta = Darken(magenta, 0.36) + light_magenta = utils.Darken(magenta, 0.36) violet = '#b751b6' cyan = '#0184bc' white = '#efefef' bg = '#fafafa' bg_alt = '#f0f0f0' - bg_highlight = Darken(bg, 0.2) + bg_highlight = utils.Darken(bg, 0.2) bg_popup = bg_alt bg_statusline = bg_popup fg = base5 fg_alt = base3 - fg_highlight = Lighten(fg, 0.2) + fg_highlight = utils.Lighten(fg, 0.2) - tag = Mix(blue, cyan, 0.5) + tag = utils.Mix(blue, cyan, 0.5) diff_info_fg = orange - diff_info_bg0 = Mix('#D8EEFD', bg, 0.6) - diff_info_bg1 = Mix('#D8EEFD', bg, 0.8) + diff_info_bg0 = utils.Mix('#D8EEFD', bg, 0.6) + diff_info_bg1 = utils.Mix('#D8EEFD', bg, 0.8) diff_add_fg = green - diff_add_fg0 = Mix(green, fg, 0.4) - diff_add_bg0 = Mix('#506d5b', bg, 0.4) - diff_add_bg1 = Mix('#acf2bd', bg, 0.8) + diff_add_fg0 = utils.Mix(green, fg, 0.4) + diff_add_bg0 = utils.Mix('#506d5b', bg, 0.4) + diff_add_bg1 = utils.Mix('#acf2bd', bg, 0.8) gh_danger_fg = red - gh_danger_fg0 = Mix(red, fg, 0.6) - gh_danger_bg0 = Mix('#ffdce0', bg, 0.8) - gh_danger_bg1 = Mix('#ffdce0', bg, 0.9) + gh_danger_fg0 = utils.Mix(red, fg, 0.6) + gh_danger_bg0 = utils.Mix('#ffdce0', bg, 0.8) + gh_danger_bg1 = utils.Mix('#ffdce0', bg, 0.9) end if vim.g.doom_one_cursor_coloring then @@ -195,7 +195,7 @@ local general_ui = { }, NormalPopupPrompt = { fg = base7, - bg = transparent_bg and 'NONE' or Darken(bg_popup, 0.3), + bg = transparent_bg and 'NONE' or utils.Darken(bg_popup, 0.3), gui = 'bold', }, NormalPopupSubtle = { diff --git a/lua/colors/utils/init.lua b/lua/colors/utils/init.lua index 04669c9..111c0e7 100644 --- a/lua/colors/utils/init.lua +++ b/lua/colors/utils/init.lua @@ -2,25 +2,24 @@ -- COLOR UTILITIES -- ---]]------------------------[[--- -local vim = vim +local M = {} ------------------------------------------------------------------------------- --- Functions: --- {{{1 +-- Functions {{{ -- Convert RGB to Hex color. -- @param r Red value -- @param g Green value -- @param b Blue value -- @return HEX color, e.g. '#1E1E1E' -function RGB_to_Hex(r, g, b) +local function RGB_to_Hex(r, g, b) return '#' .. string.format('%02X%02X%02X', r, g, b) end -- Convert Hex to RGB color. -- @param color HEX color -- @return RGB color, e.g. {30, 30, 30} -function Hex_to_RGB(color) +local function Hex_to_RGB(color) color = color:gsub('#', '') return { tonumber('0x' .. string.sub(color, 1, 2)), @@ -29,106 +28,11 @@ function Hex_to_RGB(color) } end --- Convert HUE to RGB -function Hue_to_RGB(p, q, t) - if t < 0 then - t = t + 1 - end - if t > 1 then - t = t - 1 - end - - if t < (1.0 / 6) then - return (p + (q - p) * 6.0 * t) - end - if t < (1.0 / 2) then - return q - end - if t < (2.0 / 3) then - return (p + (q - p) * 2.0 / 3 - t) * 6.0 - end - - return p -end - --- Convert HSL to RGB color. -function HSL_to_RGB(h, s, l) - local r = 0 - local g = 0 - local b = 0 - -- achromatic - if s == 0.0 then - r = l - g = l - b = l - else - local q = l < 0.5 and l * (1 + s) or l + s - l * s - local p = 2 * l - q - r = Hue_to_RGB(p, q, h + 0.33333) - g = Hue_to_RGB(p, q, h) - b = Hue_to_RGB(p, q, h - 0.33333) - end - - return { - r * 255.0, - g * 255.0, - b * 255.0, - } -end - --- Convert RGB to HSL color. --- @param red Red value --- @param green Green value --- @param blue Blue value -function RGB_to_HSL(red, green, blue) - local r = red / 255 - local g = green / 255 - local b = blue / 255 - local max = math.max(r, g, b) - local min = math.min(r, g, b) - - local h = 0.0 - local s = 0.0 - local l = (max + min) / 2 - - if max == min then - h = 0 -- achromatic - s = 0 -- achromatic - else - local d = max - min - s = (l > 0.5 and d / (2 - max - min) or d / (max + min)) - - if max == r then - h = (g - b) / d + (g < b and 6 or 0) - end - if max == g then - h = (b - r) / d + 2 - end - if max == b then - h = (r - g) / d + 4 - end - h = h / 6 - end - - return { h, s, l } -end - --- 1}}} +-- }}} ------------------------------------------------------------------------------- --- Composed functions: --- {{{1 +-- Composed functions {{{ -function Hex_to_HSL(color) - local r, g, b = Hex_to_RGB(color) - return RGB_to_HSL(r, g, b) -end - -function HSL_to_Hex(h, s, l) - local r, g, b = HSL_to_RGB(h, s, l) - return RGB_to_Hex(r, g, b) -end - -function Lighten(color, percentage) +M.Lighten = function(color, percentage) local amount = percentage == nil and 5.0 or percentage if amount < 1.0 then @@ -153,7 +57,7 @@ function Lighten(color, percentage) return hex end -function Darken(color, percentage) +M.Darken = function(color, percentage) local amount = percentage == nil and 5.0 or percentage if amount < 1.0 then @@ -186,7 +90,7 @@ local function interpolate(start, _end, amount) return start + (diff * amount) end -function Mix(first, second, percentage) +M.Mix = function(first, second, percentage) local amount = percentage == nil and 0.0 or percentage local first_rgb = Hex_to_RGB(first) @@ -198,4 +102,8 @@ function Mix(first, second, percentage) return RGB_to_Hex(r, g, b) end --- 1}}} +-- }}} + +return M + +-- vim: fdm=marker