Function: color-rgb-to-hex
color-rgb-to-hex is a byte-compiled function defined in color.el.gz.
Signature
(color-rgb-to-hex RED GREEN BLUE &optional DIGITS-PER-COMPONENT)
Documentation
Return hexadecimal #RGB notation for the color specified by RED GREEN BLUE.
RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive. Optional argument DIGITS-PER-COMPONENT can be either 4 (the default) or 2; use the latter if you need a 24-bit specification of a color.
Source Code
;; Defined in /usr/src/emacs/lisp/color.el.gz
(defun color-rgb-to-hex (red green blue &optional digits-per-component)
"Return hexadecimal #RGB notation for the color specified by RED GREEN BLUE.
RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive.
Optional argument DIGITS-PER-COMPONENT can be either 4 (the default)
or 2; use the latter if you need a 24-bit specification of a color."
(or digits-per-component (setq digits-per-component 4))
(let* ((maxval (if (= digits-per-component 2) 255 65535))
(fmt (if (= digits-per-component 2) "#%02x%02x%02x" "#%04x%04x%04x")))
(format fmt (* red maxval) (* green maxval) (* blue maxval))))