1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\startMPcalculation{simplefun}
17
18 path kaktovik_glyphs[] ;
19
20 def InitializeKaktovik =
21
22 save p, d, u ;
23
24 pair p[] ; numeric d ; d := .1 ; numeric u ; u := .15 ;
25
26
27
28
29 p[0] := (0,1) ;
30 p[1] := (1,0) ;
31 p[2] := (2,1 d) ;
32 p[3] := (3,0) ;
33 p[4] := (4,1 2d) ;
34
35 p[5] := (4,1 u) ;
36 p[6] := (0,1 2u) ;
37 p[7] := (4,1 4u) ;
38
39 kaktovik_glyphs[0] := (1,1) { right } .. { left } (2,12) { left } .. { right } (3,1);
40
41 for i= 1 upto 4 :
42 kaktovik_glyphs[i] := p[0] for j=1 upto i : -- p[j] endfor ;
43 endfor ;
44
45 kaktovik_glyphs[ 5] := p[5] -- p[0] ; for i= 6 upto 9 : kaktovik_glyphs[i] := p[5] -- kaktovik_glyphs[i-5] ; endfor ;
46 kaktovik_glyphs[10] := p[6] -- kaktovik_glyphs[ 5] ; for i=11 upto 14 : kaktovik_glyphs[i] := p[6] -- kaktovik_glyphs[i-5] ; endfor ;
47 kaktovik_glyphs[15] := p[7] -- kaktovik_glyphs[10] ; for i=16 upto 19 : kaktovik_glyphs[i] := p[7] -- kaktovik_glyphs[i-5] ; endfor ;
48
49 enddef ;
50
51 vardef Kaktovik(expr i) =
52 draw image (
53 draw kaktovik_glyphs[i]
54 xscaled (1020 -120)
55 yscaled (2520 -220)
56 withpen (pencircle xscaled 120 yscaled 520) rotated (220)
57
58
59 ;
60 ) shifted (220,220)
61 enddef ;
62
63 lmt_registerglyphs [
64 name = "kaktovik",
65 units = 2,
66 usecolor = true,
67 width = 2,
68 height = 2,
69 depth = 0,
70 preamble = "InitializeKaktovik"
71 ] ;
72
73 for i=0 upto 19 :
74 lmt_registerglyph [
75 category = "kaktovik",
76 unicode = 119488 i,
77 code = "Kaktovik(" & decimal i & ")"
78 ] ;
79 endfor ;
80
81\stopMPcalculation
82
83\startluacode
84 local kaktovik = moduledata.kaktovik or { }
85 moduledata.kaktovik = kaktovik
86
87 local tonumber = tonumber
88 local load = load
89 local reverse = table.reverse
90 local utfchar = utf.char
91 local gsub = string.gsub
92 local concat = table.concat
93 local utfvalues = string.utfvalues
94 local lpegmatch = lpeg.match
95
96 function kaktovik.tointeger(s)
97 local n = 0
98 for b in utfvalues(s) do
99 local k = b - 0x1D2C0
100 n = n * 20 + k
101 end
102 return n
103 end
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 local f = string.formatters["%N"]
120
121 function kaktovik.tostring(n)
122 if n >= 0 and n <= 19 then
123 return utfchar(0x1D2C0 + n)
124 else
125
126 local result = gsub(f(n),"(%d+)",function(s)
127 local digits = { }
128 local count = 1
129 local n = tonumber(s)
130 while true do
131 digits[count] = utfchar(0x1D2C0 + (n % 20))
132 n = n // 20
133 if n == 0 then
134 break;
135 end
136 count = count + 1
137 end
138 return concat(reverse(digits))
139 end)
140 return result
141 end
142 end
143
144 do
145
146 local k = { }
147 local n = 0
148 for i=0x1D2C0,0x1D2C0+19 do
149 k[utf.char(i)] = n
150 n = n + 1
151 end
152
153 local p = lpeg.Cs (
154 lpeg.Cc("return ")
155 * (
156 lpeg.utfchartabletopattern(k) / k
157 + lpeg.P(1)
158 )^0
159 )
160
161 local t = setmetatable({ },{ __index = math })
162
163 function kaktovik.calculate(old)
164 local new = lpegmatch(p,old)
165 if new then
166 new = load(new,nil,nil,t)
167 if type(new) == "function" then
168 new = new()
169 if new then
170 return new
171 end
172 end
173 end
174 return old
175 end
176
177 end
178
179 interfaces.implement {
180 name = "kaktoviknumerals",
181 arguments = "integer",
182 actions = { kaktovik.tostring, context }
183 }
184
185 interfaces.implement {
186 name = "kaktovikcalculate",
187 public = true,
188 arguments = "string",
189 actions = { kaktovik.calculate, kaktovik.tostring, context }
190 }
191\stopluacode
192
193\unprotect
194
195\permanent\def\kaktoviknumerals#1{\clf_kaktoviknumerals\numexpr#1\relax}
196
197\defineconversion [kaktoviknumerals] [\kaktoviknumerals]
198\defineconversion [K] [\kaktoviknumerals]
199
200\definefontfeature
201 [kaktovik]
202 [metapost=kaktovik]
203
204\protect
205
206\continueifinputfile{metaimpkaktovik.mkxl}
207
208\startbuffer
209
210\definefontfeature
211 [default]
212 [default]
213 [metapost=kaktovik]
214
215
216\setupbodyfont[dejavu]
217
218
219
220\start
221 \showglyphs
222 KAKTOVIK
223 \dostepwiserecurse{0}{19}{1}{\kaktoviknumerals{#1}\space }
224\stop
225
226kaktovik \start
227 \red\glyphxscale 700
228 \dostepwiserecurse{0}{19}{1}{\kaktoviknumerals{#1}\space }
229\stop
230
231\startitemize[packed,K][color=orange,stopper=]
232 \startitem first \stopitem
233 \startitem second \stopitem
234 \startitem third \stopitem
235\stopitemize
236
237KAKTOVIK \start
238 \red \kaktoviknumerals{2023}
239 \green\kaktoviknumerals{4}
240 \blue \kaktoviknumerals{18}
241\stop
242
243KAKTOVIK
244
245𝋂 𝋂 = \kaktovikcalculate{𝋂 𝋂} = \kaktoviknumerals{4}
246
247\protected\def\ForWilli#1{#1 = \kaktovikcalculate{#1}}
248
249\ForWilli{(𝋂 𝋂) (𝋂 𝋂)}
250
251\ForWilli{(sin ( 𝋂𝋓 ) )}
252
253\stopbuffer
254
255\starttext
256
257\startTEXpage[offset=1ts,width=3es]
258 \getbuffer
259\stopTEXpage
260
261\setuplayout[tight]
262
263\usemodule[scite]
264
265\typebuffer[option=TEX]
266
267\stoptext
268 |