-
-
Save galdor/3844e62f299aaffa55a7dd48a7cf0911 to your computer and use it in GitHub Desktop.
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 g-hsl-to-rgb (string) | |
"Convert a HSL color string (e.g. \"hsl(200, 40%, 80%)\") to an | |
RGB color string (e.g. \"#e0b7b7\")." | |
(when (string-match | |
"^hsl( *\\([0-9]+\\) *, *\\([0-9]+\\)% *, *\\([0-9]+\\)% *)$" string) | |
(let* ((h (/ (string-to-number (match-string 1 string)) 360.0)) | |
(s (/ (string-to-number (match-string 2 string)) 100.0)) | |
(l (/ (string-to-number (match-string 3 string)) 100.0)) | |
(rgb (color-hsl-to-rgb h s l)) | |
(r (cl-first rgb)) | |
(g (cl-second rgb)) | |
(b (cl-third rgb))) | |
(color-rgb-to-hex r g b 2)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment