-
Notifications
You must be signed in to change notification settings - Fork 35
/
colors.lisp
37 lines (33 loc) · 1.56 KB
/
colors.lisp
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
29
30
31
32
33
34
35
36
37
(in-package :opticl-color)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun whitespace-p (char)
(member char '(#\Space #\Tab)))
(defun trim-leading-whitespace (str)
(let ((pos (position-if-not #'whitespace-p str)))
(subseq str pos))))
(macrolet ((frob-colors ()
(let ((file (merge-pathnames
"rgb.txt"
(asdf:component-pathname
(asdf:find-system "opticl")))))
(with-open-file (stream file)
`(progn
,@(loop for r = (read stream nil nil)
while r
collect
(let ((g (read stream))
(b (read stream))
(color
(concatenate 'string
"*"
(substitute-if
#\- #'whitespace-p
(trim-leading-whitespace
(read-line stream)))
"*")))
(let ((sym (read-from-string color)))
`(progn
(defparameter ,sym (list ,r ,g ,b))
(eval-when (:compile-toplevel :load-toplevel :execute)
(export ',sym)))))))))))
(frob-colors))