Skip to content

Instantly share code, notes, and snippets.

@tek-nishi
Last active August 29, 2015 14:20
Show Gist options
  • Save tek-nishi/f23094549af99f623f0a to your computer and use it in GitHub Desktop.
Save tek-nishi/f23094549af99f623f0a to your computer and use it in GitHub Desktop.
Convert from RGB to HSV (Emacs)
(defun my-color-rgb-to-hsv (r g b)
"RGB[0.0, 1.0]からHSV[0.0, 1.0]へ変換する (SOURCE:Wikipedia)"
(let* ((max (max r g b))
(min (min r g b))
(h (- max min))
(s (- max min))
(v max))
(if (> h 0.0)
(cond ((= max r)
(progn
(setq h (/ (- g b) h))
(if (< h 0.0)
(setq h (+ 6.0)))))
((= max g)
(setq h (+ 2.0 (/ (- b r) h))))
(t
(setq h (+ 4.0 (/ (- r g) h))))))
(setq h (/ h 6.0))
(if (/= max 0)
(setq s (/ s max)))
(list h s v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment