=== modified file 'lisp/ChangeLog' *** lisp/ChangeLog 2013-03-27 16:03:15 +0000 --- lisp/ChangeLog 2013-03-28 14:36:48 +0000 *************** *** 1,3 **** --- 1,7 ---- + 2013-03-28 Jambunathan K + + * color.el (color-hsv-to-rgb): New defun. + 2013-03-27 Eli Zaretskii * facemenu.el (list-colors-callback): New defvar. === modified file 'lisp/color.el' *** lisp/color.el 2013-01-11 15:04:24 +0000 --- lisp/color.el 2013-03-28 14:40:31 +0000 *************** *** 118,123 **** --- 118,148 ---- "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 HSV color components to RGB. + HUE should be in radians between 0 and 2*`float-pi', inclusive. + SATURATION and VALUE should be between 0.0 and 1.0, inclusive. + Return a list (RED GREEN BLUE) where each of the components is + between 0.0 and 1.0, inclusive." + ;; Convert h from radians to degrees + (setq h (/ (* 180.0 h) float-pi)) + (when (>= h 360) (setq h 0.0)) + (if (zerop s) + (list v v v) + (let* ((h (/ h 60.0)) + (i (floor h)) + (f (- h i)) + (l (* v (- 1 s))) + (m (* v (- 1 (* s f)))) + (n (* v (- 1 (* s (- 1 f)))))) + (cond + ((= i 0) (list v n l)) + ((= i 1) (list m v l)) + ((= i 2) (list l v n)) + ((= i 3) (list l m v)) + ((= i 4) (list n l v)) + ((= i 5) (list v l m)))))) + (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,