Skip to content

Instantly share code, notes, and snippets.

@lgaff
Created May 6, 2022 04:31
Show Gist options
  • Save lgaff/95207ea9ea24c8eccff05b6c82700710 to your computer and use it in GitHub Desktop.
Save lgaff/95207ea9ea24c8eccff05b6c82700710 to your computer and use it in GitHub Desktop.
Convert HSV to RGB
(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