Skip to content

Commit 1e02a2f

Browse files
author
skywind3000
committed
blend
1 parent 4c6ff12 commit 1e02a2f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

autoload/quickui/palette.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,25 @@ function! quickui#palette#name2index(name, ...)
447447
endfunc
448448

449449

450+
"----------------------------------------------------------------------
451+
" alpha blend
452+
"----------------------------------------------------------------------
453+
function! quickui#palette#blend(c1, c2, alpha)
454+
let c1 = a:c1
455+
let c2 = a:c2
456+
let alpha = a:alpha
457+
if type(c1) == 0 && type(c2) == 0
458+
return (c1 * (255 - alpha) + c2 * alpha) / 255
459+
endif
460+
let dst = quickui#palette#hex2rgb(c1)
461+
let src = quickui#palette#hex2rgb(c2)
462+
let r = (dst[0] * (255 - alpha) + src[0] * alpha) / 255
463+
let g = (dst[1] * (255 - alpha) + src[1] * alpha) / 255
464+
let b = (dst[2] * (255 - alpha) + src[2] * alpha) / 255
465+
return printf('#%02x%02x%02x', r, g, b)
466+
endfunc
467+
468+
450469
"----------------------------------------------------------------------
451470
" benchmark
452471
"----------------------------------------------------------------------

0 commit comments

Comments
 (0)