-
Notifications
You must be signed in to change notification settings - Fork 3
/
day08_viz.clj
62 lines (48 loc) · 1.36 KB
/
day08_viz.clj
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
(ns day08-viz
(:require aoc
aoc-viz
day08
[quil.core :as q]
[quil.middleware :as m]))
(def scale 10)
(def width 50)
(def height 6)
(def bg-color [15 15 33])
(def fg-color [255 255 96])
(def instructions (aoc/read-input 8 day08/parse-line))
(defn put-pixels [instructions]
(reductions
(fn [screen [command a b]]
(case command
:rect (day08/create screen a b)
(day08/rotate screen command a b)))
(repeat height (repeat width " "))
instructions))
(def all-screens (put-pixels instructions))
(defn setup []
(q/frame-rate 10)
(q/smooth)
(q/background 15 15 33)
all-screens)
(defn frame-update [screens]
(if (empty? screens)
(do
(q/delay-frame 3000)
(q/exit))
(rest screens)))
(defn draw-screen [screens]
(let [screen (first screens)]
(doseq [[y line] (map-indexed vector screen)
[x char] (map-indexed vector line)]
(q/with-fill (case char
" " bg-color
"#" fg-color)
(aoc-viz/scaled-square x y scale)
#_(q/save-frame "/tmp/imgs/day08-####.jpg")))))
(q/sketch
:size [(* scale width) (* scale height)]
:setup #'setup
:update #'frame-update
:draw #'draw-screen
:middleware [m/fun-mode])
; convert -layers optimize -delay 10 /tmp/imgs/day08*.jpg -delay 300 /tmp/imgs/day08-0154.jpg imgs/day08.gif