Last active
August 29, 2015 14:20
-
-
Save tek-nishi/f23094549af99f623f0a to your computer and use it in GitHub Desktop.
Convert from RGB to HSV (Emacs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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