From 7a8aa2c501c7ff6ce90c3f070e8732490e663d7f Mon Sep 17 00:00:00 2001 From: gryf Date: Tue, 19 Jan 2021 18:58:35 +0100 Subject: [PATCH] Update rgb_number function --- colors/wombat256grf.vim | 47 +++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/colors/wombat256grf.vim b/colors/wombat256grf.vim index 18ecc29..12b7313 100644 --- a/colors/wombat256grf.vim +++ b/colors/wombat256grf.vim @@ -80,30 +80,27 @@ fun s:get_grey_color_idx(n) endfun " returns an approximate color index for the given color level -fun rgb_number(x) +fun s:get_approximate_rgb_idx(x) if &t_Co == 88 - if a:x < 69 - return 0 - elseif a:x < 172 - return 1 - elseif a:x < 230 - return 2 - else - return 3 - endif - else - if a:x < 75 - return 0 - else - let l:n = (a:x - 55) / 40 - let l:m = (a:x - 55) % 40 - if l:m < 20 - return l:n - else - return l:n + 1 + let l:rgb_map = {69: 0, 172: 1, 230: 2} + for i in sort(keys(l:rgb_map), "s:sort_ints") + if a:x < i + return l:rgb_map[i] endif - endif + endfor + return 3 endif + + if a:x < 75 + return 0 + endif + + let l:n = (a:x - 55) / 40 + let l:m = (a:x - 55) % 40 + if l:m < 20 + return l:n + endif + return l:n + 1 endfun " returns the actual color level for the given color index @@ -144,9 +141,9 @@ fun color(r, g, b) let l:gz = s:get_approximate_grey_idx(a:b) " get the closest color - let l:x = rgb_number(a:r) - let l:y = rgb_number(a:g) - let l:z = rgb_number(a:b) + let l:x = s:get_approximate_rgb_idx(a:r) + let l:y = s:get_approximate_rgb_idx(a:g) + let l:z = s:get_approximate_rgb_idx(a:b) if l:gx == l:gy && l:gy == l:gz " there are two possibilities @@ -340,7 +337,7 @@ delf rgb delf color delf rgb_color delf rgb_level -delf rgb_number +delf s:get_approximate_rgb_idx delf s:get_grey_color_idx delf s:get_grey_level delf s:get_approximate_grey_idx