-
Notifications
You must be signed in to change notification settings - Fork 1
/
colors-256.scm
68 lines (59 loc) · 2.08 KB
/
colors-256.scm
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
; vim: set expandtab:
(declare (unit colors-256))
(module colors-256
(keyframe
keyframes
special-colors
prime-colors)
(import
ansi-escape-sequences
(chicken base)
scheme
srfi-1)
(define (keyframe i frames)
(define (proportional+ p rgb1 rgb2)
(list (round (+ (* (- 1 p) (list-ref rgb1 0)) (* p (list-ref rgb2 0))))
(round (+ (* (- 1 p) (list-ref rgb1 1)) (* p (list-ref rgb2 1))))
(round (+ (* (- 1 p) (list-ref rgb1 2)) (* p (list-ref rgb2 2))))))
; locate the segment in which i lies
(cond
((<= i (caar keyframes))
(cadar keyframes))
((> i (car (last keyframes)))
(cadr (last keyframes)))
(else
(let-values (((low high)
(let loop ((head (car keyframes)) (tail (cdr keyframes)))
(if (<= i (caar tail))
(values head (car tail))
(loop (car tail) (cdr tail))))))
;(print "low:" low " high:" high)
(let* ((proportion (/ (- i (car low)) (- (car high) (car low)))))
(proportional+ proportion (cadr low) (cadr high)))))))
; this list should be sorted on keyframe index
(define keyframes
'((20 (#xff #x00 #xff)) ;magenta
(30 (#xff #x00 #x00)) ;red
(40 (#xff #xff #x00)) ;yellow
(50 (#x00 #xff #x00)) ;green
(60 (#x00 #xff #xff)) ;cyan
(70 (#x00 #x00 #xff)) ;blue
(90 (#xb0 #xb0 #xb0)) ;pale grey
(101 (#x50 #x50 #x50))));dim grey
; re-define some of the colors in the terminal's 6x6x6 color cube
(do ((i 20 (add1 i)))
((= i 102))
(let ((color (keyframe i keyframes)))
(print* (set-color256! i
(first color)
(second color)
(third color)))))
;; Prepare the color cycle for output
(define special-colors
; form a list of the extended 256 color codes
(let loop ((i 20))
(if (= i 101)
(circular-list `(bold (foreground ,i)))
(cons `(bold (foreground ,i)) (loop (add1 i))))))
(define prime-colors (drop special-colors 10))
); module