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
;; Something to output a Plan 9 color palette according to
;; https://9p.io/magic/man2html/6/color
;; I couldn't heckin' imagine it, so I had to see it visually.
;; Written in Fennel: https://fennel-lang.org/
;;
;; By icefox@dreamquest.io
;; License: MIT
(fn generate-palette []
"Generates the palette, returning a list of [r g b] values"
(var palette [])
(var r 0)
(var g 0)
(var b 0)
(var v 0)
(var num 0)
(var denom 0)
(for [r 0 3]
(for [v 0 3]
(for [g 0 3]
(for [b 0 3]
(var color [0 0 0])
(set denom r)
(if (> g denom) (set denom g))
(if (> b denom) (set denom b))
; Check for divide by 0, pick grey
(if (= denom 0)
(let [c (* 17 v)]
(table.insert palette [c c c]))
(let [num (* 17 (+ (* 4 denom) v))]
(table.insert
palette
[(// (* r num) denom)
(// (* g num) denom)
(// (* b num) denom)])))))))
palette)
(local fennel (require :fennel))
; Ok now I guess we're just gonna print these out as html
(print "<html><head></head><body>")
(print "<table>")
;(each [_i color (ipairs (generate-palette))]
; (let [color-str (string.format "#%02X%02X%02X" (. color 1) (. color 2) (. color 3))]
; (print (string.format "<tr><td style=\"padding: 1em; background-color:%s\">" color-str))
; (print color-str)
; (print "</td></tr>")))
(local colors (generate-palette))
(for [x 1 15]
(print "<tr>")
(for [y 1 16]
(let [color (. colors (+ y (* x 16)))
color-str (string.format "#%02X%02X%02X" (. color 1) (. color 2) (. color 3))]
(print (string.format "<td style=\"padding: 1em; background-color:%s\">" color-str))
(print color-str)
(print "</td>")))
(print "</tr>"))
(print "</table>")
(print "</body></html>")