forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typograf.carp
109 lines (94 loc) · 3.23 KB
/
typograf.carp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
;; A dynamic font
(import gl)
(def gstate 65)
(defn mid-x [] 256f)
(defn mid-y [] 256f)
(defn em [] 100f)
(defn en [] 70f)
(defn point-for-id [i]
(copy
(nth
(ref [(Vec2 (mid-x) (mid-y))
(Vec2 (mid-x) (- (mid-y) (em)))
(Vec2 (+ (mid-x) (em)) (- (mid-y) (en)))
(Vec2 (+ (mid-x) (em)) (mid-y))
(Vec2 (+ (mid-x) (em)) (+ (mid-y) (en)))
(Vec2 (mid-x) (+ (mid-y) (em)))
(Vec2 (- (mid-x) (em)) (+ (mid-y) (en)))
(Vec2 (- (mid-x) (em)) (mid-y))
(Vec2 (- (mid-x) (em)) (- (mid-y) (en)))])
@i)))
;; 1
;; / \
;; 8 2
;; | |
;; 7 0 3
;; | |
;; 6 4
;; \ /
;; 5
(defstruct TypografGlyph
[point-ids (:Array :int)])
(defn int->glyph [x]
(let [glyphs [(TypografGlyph [8 1 2 3 7 6 5 4 3]) ;; a
(TypografGlyph [8 7 6 5 4 3 7]) ;; b
(TypografGlyph [1 8 7 6 5]) ;; c
(TypografGlyph [2 3 7 6 5 4 3]) ;; d
(TypografGlyph [7 3 2 1 8 6 5 4]) ;; e
(TypografGlyph [2 1 0 7 0 3 0 5]) ;; f
(TypografGlyph [2 1 8 7 6 5 4 3 0]) ;; g
(TypografGlyph [8 7 6 7 3 2 4]) ;; h
(TypografGlyph [1 5]) ;; i
(TypografGlyph [1 5 6]) ;; j
(TypografGlyph [6 8 7 2 7 4]) ;; k
(TypografGlyph [1 5 4]) ;; l
(TypografGlyph [6 8 0 2 4]) ;; m
(TypografGlyph [6 8 4 2]) ;; n
(TypografGlyph [1 2 3 4 5 6 7 8 1]) ;; o
(TypografGlyph [5 1 2 0]) ;; p
(TypografGlyph [1 3 6 4 5 8 7 2 1]) ;; q
(TypografGlyph [6 8 1 2 0 7 0 4]) ;; r
(TypografGlyph [2 1 8 0 4 5 6]) ;; s
(TypografGlyph [5 0 7 3]) ;; t
(TypografGlyph [8 7 6 5 4 3 2]) ;; u
(TypografGlyph [8 5 2]) ;; v
(TypografGlyph [8 6 0 4 2]) ;; w
(TypografGlyph [8 4 0 2 6]) ;; x
(TypografGlyph [8 0 2 0 5]) ;; y
(TypografGlyph [8 2 6 4]) ;; z
]
i (- x 65)]
(if (< i (count &glyphs))
(copy (nth &glyphs i))
(TypografGlyph []))))
(defn draw-glyph [glyph]
(let [ids (TypografGlyph-get-point-ids glyph)
points (map-copy point-for-id ids)]
(draw-lines &points)))
(defn draw [whatever]
(let [glyph (int->glyph gstate)]
(do
(glColor3f 0.3f 0.2f 0.2f)
(draw-line 0f 256f 512f 256f)
(draw-circle 256f 256f 225f)
(glColor3f 1f 1f 1f)
(draw-glyph &glyph))))
^ann glfw-key-callback-type
(defn on-keys [window key scancode action mods]
(if (= key-esc key)
(glfwSetWindowShouldClose window true)
(reset! gstate key)))
(defn setup []
(do
;;(reset! gstate 65)
(glOrtho 0.0 512.0 512.0 0.0 1.0 -1.0) 0))
(defn update [x]
x)
;; (if (< gstate (+ 65 25))
;; (reset! gstate (inc gstate))
;; (reset! gstate 65))
(defn typograf []
(glfw-app "Typograf" setup update draw on-keys))
;;(bake-exe typograf)
;;(bake typograf)
;;(typograf)