mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
Add color-blend to blend two RGB lists
* lisp/color.el (color-blend): Blend two RGB lists. * test/lisp/color-tests.el (color-tests-blend): Test color-blend. * etc/NEWS: Announce color-blend.
This commit is contained in:
parent
e1e8da5e4f
commit
bf312529de
3 changed files with 27 additions and 0 deletions
5
etc/NEWS
5
etc/NEWS
|
|
@ -732,6 +732,11 @@ restore the old behavior, you can set 'eshell-pwd-convert-function' to
|
|||
This function natively-compiles all Lisp files in a directory and in its
|
||||
sub-directories, recursively, which were not already natively-compiled.
|
||||
|
||||
---
|
||||
** New function 'color-blend'.
|
||||
This function takes two RGB lists and optional ALPHA and returns an RGB
|
||||
list whose elements are blended in linear space proportional to ALPHA.
|
||||
|
||||
+++
|
||||
** The 'defcustom' ':local' keyword can now be 'permanent-only'.
|
||||
This means that the variable's 'permanent-local' property is set to t,
|
||||
|
|
|
|||
|
|
@ -75,6 +75,22 @@ components (e.g. \"#ffff1212ecec\")."
|
|||
(- 1.0 (nth 1 color))
|
||||
(- 1.0 (nth 2 color)))))
|
||||
|
||||
(defun color-blend (a b &optional alpha)
|
||||
"Blend the two colors A and B in linear space with ALPHA.
|
||||
A and B should be lists (RED GREEN BLUE), where each element is
|
||||
between 0.0 and 1.0, inclusive. ALPHA controls the influence A
|
||||
has on the result and should be between 0.0 and 1.0, inclusive.
|
||||
|
||||
For instance:
|
||||
|
||||
(color-blend '(1 0.5 1) '(0 0 0) 0.75)
|
||||
=> (0.75 0.375 0.75)"
|
||||
(setq alpha (or alpha 0.5))
|
||||
(let (blend)
|
||||
(dotimes (i 3)
|
||||
(push (+ (* (nth i a) alpha) (* (nth i b) (- 1 alpha))) blend))
|
||||
(nreverse blend)))
|
||||
|
||||
(defun color-gradient (start stop step-number)
|
||||
"Return a list with STEP-NUMBER colors from START to STOP.
|
||||
The color list builds a color gradient starting at color START to
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@
|
|||
(should (equal (color-complement "#ffffffffffff") '(0.0 0.0 0.0)))
|
||||
(should (equal (color-complement "red") '(0.0 1.0 1.0))))
|
||||
|
||||
(ert-deftest color-tests-blend ()
|
||||
(should (equal (color-blend '(1.0 0.0 0.0) '(0.0 1.0 0.0)) '(0.5 0.5 0.0)))
|
||||
(should (equal (color-blend '(1.0 1.0 1.0) '(0.0 1.0 0.0)) '(0.5 1.0 0.5)))
|
||||
(should (equal (color-blend '(0.0 0.39215686274509803 0.0) '(0.9607843137254902 0.8705882352941177 0.7019607843137254))
|
||||
'(0.4803921568627451 0.6313725490196078 0.3509803921568627))))
|
||||
|
||||
(ert-deftest color-tests-gradient ()
|
||||
(should-not (color-gradient '(0 0 0) '(255 255 255) 0))
|
||||
(should
|
||||
|
|
|
|||
Loading…
Reference in a new issue