Function: color-gradient

color-gradient is a byte-compiled function defined in color.el.gz.

Signature

(color-gradient START STOP STEP-NUMBER)

Documentation

Return a list with STEP-NUMBER colors from START to STOP.

The color list builds a color gradient starting at color START to color STOP. It does not include the START and STOP color in the resulting list.

Source Code

;; Defined in /usr/src/emacs/lisp/color.el.gz
(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
color STOP.  It does not include the START and STOP color in the
resulting list."
  (let* ((r (nth 0 start))
	 (g (nth 1 start))
	 (b (nth 2 start))
         (interval (float (1+ step-number)))
	 (r-step (/ (- (nth 0 stop) r) interval))
	 (g-step (/ (- (nth 1 stop) g) interval))
	 (b-step (/ (- (nth 2 stop) b) interval))
	 result)
    (dotimes (_ step-number)
      (push (list (setq r (+ r r-step))
		  (setq g (+ g g-step))
		  (setq b (+ b b-step)))
	    result))
    (nreverse result)))