Created
May 6, 2022 04:31
-
-
Save lgaff/95207ea9ea24c8eccff05b6c82700710 to your computer and use it in GitHub Desktop.
Convert HSV to RGB
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
(define (hsv-to-rgb hue saturation value) | |
(let* ([C (* saturation value)] | |
[A (abs (- (modulo (/ hue 60) 2) | |
1))] | |
[X (* (- 1 A))] | |
[m (- value C)] | |
[rgb-prime | |
(cond | |
[(<= 0 hue 59) `(,C ,X 0)] | |
[(<= 60 hue 119) `(,X ,C 0)] | |
[(<= 120 hue 179) `(0 ,C ,X)] | |
[(<= 180 hue 239) `(0 ,X ,C)] | |
[(<= 240 hue 299) `(,X 0 ,C)] | |
[(<= 300 hue 359) `(,C 0 ,X)])]) | |
(map (λ (v) (* 255 (+ v m))) rgb-prime))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment