File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,8 +74,13 @@ for c in range(0, 23)
7474 let s: colortable += [[value, value, value]]
7575endfor
7676
77- function ! s: square (x )
78- return a: x * a: x
77+ function ! s: distance (c1,c2)
78+ let [r1,g1,b1] = a: c1
79+ let [r2,g2,b2] = a: c2
80+ let dr = r2 - r1
81+ let dg = g2 - g1
82+ let db = b2 - b1
83+ return dr * dr + dg * dg + db* db
7984endfunction
8085
8186" selects the nearest xterm color for a rgb value like #FF0000
@@ -86,8 +91,10 @@ function! s:Rgb2xterm(color)
8691 let r = s: hex [color [1 :2 ]]
8792 let g = s: hex [color [3 :4 ]]
8893 let b = s: hex [color [5 :6 ]]
94+ unlet color
95+ let color = [r ,g ,b ]
8996 for c in range (0 ,255 )
90- let d = s: square ( s: colortable [ c ][ 0 ] - r ) + s: square ( s: colortable [c ][ 1 ] - g ) + s: square ( s: colortable [ c ][ 2 ] - b )
97+ let d = s: distance ( color , s: colortable [c ])
9198 if d == 0 | return c | endif
9299 if d < smallest_distance
93100 let smallest_distance = d
You can’t perform that action at this time.
0 commit comments