diff --git a/lisp/color.el b/lisp/color.el index f68cf5e6b17..37f11f23c7c 100644 --- a/lisp/color.el +++ b/lisp/color.el @@ -123,6 +123,26 @@ color-complement-hex "Return the color that is the complement of COLOR, in hexadecimal format." (apply 'color-rgb-to-hex (color-complement color))) +(defun color-hsv-to-rgb (H S V) + "Convert hue, saturation and value to their RGB representation. +H, S, and V should each be numbers between 0.0 and 1.0, inclusive. +Return a list (RED GREEN BLUE), where each element is between 0.0 and 1.0, +inclusive." + (let* ((I (floor (* 6 H))) + (F (- (* H 6) I)) + (P (* V (- 1.0 S))) + (Q (* V (- 1.0 (* F S)))) + (T (* V (- 1.0 (* (- 1.0 F) S)))) + (I (mod I 6))) + (cond + ((= I 0) (list V T P)) + ((= I 1) (list Q V P)) + ((= I 2) (list P V T)) + ((= I 3) (list P Q V)) + ((= I 4) (list T P V)) + ((= I 5) (list V P Q)) + (t (list 0 0 0))))) + (defun color-rgb-to-hsv (red green blue) "Convert RGB color components to HSV. RED, GREEN, and BLUE should each be numbers between 0.0 and 1.0,