summaryrefslogtreecommitdiff
path: root/color.lisp
blob: d9ed8002c05465f706bc62fe5ec95f7c45af776c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(in-package #:color)

(defun hsl->rgb (h s l)
  (let* ((c (* (- 1 (abs (- (* 2 l) 1))) s))
         (x (* c (- 1 (abs (- (mod (/ h 60) 2) 1)))))
         (m (- l (/ c 2)))
         (r m)
         (g m)
         (b m))
    (cond ((<= 0 h 59)
           (incf r c)
           (incf g x))
          ((<= 60 h 119)
           (incf r x)
           (incf g c))
          ((<= 120 h 179)
           (incf g c)
           (incf b x))
          ((<= 180 239)
           (incf g x)
           (incf b c))
          ((<= 240 299)
           (incf r x)
           (incf b c))
          ((<= 300 359)
           (incf r c)
           (incf b x)))
    (values r g b)))