-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal.html
582 lines (551 loc) · 7.64 KB
/
minimal.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!doctype html>
<meta charset='utf-8'/>
<meta name='viewport' content='width=device-width' />
<meta name='theme-color' content='#000000'/>
<title>
Minimal
</title>
<style type='text/css'>
:root {color-scheme: dark;}
body, input, select {
background: #000;
color: #FFF;
display: flex;
flex-direction: column;
font-family: sans-serif;
font-size: 1em;
margin: 0;
}
label {
display: flex;
}
input, select, .label {
border: 0;
opacity: 0.5;
padding: .5em;
}
select {
flex-grow: 1;
}
</style>
<input id='offset' title='Demo Offset' value='0' type='range' max='86400000' step='100000' onInput='synchronize()'>
<label>
<span class='label'>Theme</span>
<select id='theme' onChange='setTheme(this.value)'></select>
</label>
<div><canvas id='face'></canvas></div>
<script type='text/javascript'>
const eid = document.getElementById.bind(document)
let font = 'blockString'
let palettes
const color_palettes = {
'black': {
1: '#000000',
},
'gray_1_3': {
1: '#F85030',
},
'gray_2_3': {
1: '#60F858',
},
'white': {
1: '#FFFFFF',
},
}
const four_negative = ['black', 'gray_1_3', 'gray_2_3', 'white']
const four_positive = [...four_negative].reverse()
const themes = {
Dark: {
_scale: four_negative,
_body: '3',
background: color_palettes.black[1],
},
Light: {
_scale: four_positive,
_body: '3',
background: color_palettes.white[1],
},
}
for(k in themes){
const theme = themes[k]
;(theme._scale||[]).forEach((color, i)=>theme[i] = color_palettes[color])
Object.assign(theme, color_palettes)
}
eid('theme').innerHTML = Object.keys(themes).map(t => `<option value='${t}'>${t}</option>`).join('')
const locale = 'en-us'
const months = ['JAN.', 'FEB.', 'MAR.', 'APR.', 'MAY', 'JUNE', 'JULY', 'AUG.', 'SEPT', 'OCT.', 'NOV.', 'DEC.']
const _ = void 0
const can = eid('face')
const c = can.getContext('2d')
const height = 144
const width = 160
const pad_h = 11
const pad_v = 19
// zoom dev
const z = 4
can.height = height * z
can.width = width * z
// can.style.height = height + 'px';
// can.style.width = width + 'px';
c.setTransform(z, 0, 0, z, 0, 0)
const offset_el = eid('offset')
const sym_w = 5
const sym_a = sym_w * sym_w
const sym_w2 = sym_w * 2
const g = sym_w + 1
const g2 = g * 2
const {ceil, floor, random} = Math
const tiles_h = ceil(width / g * .5)
const tiles_v = ceil(height / g * .5) - 1
const slots_h = floor((width - pad_h) / g)
// const slots_v = floor((height - pad_v) / g)
// base-2 for single color pixel font
// base-3 for 1 extra color, and so forth
// base-36 for text storage
function encode_font(font){
return Object.fromEntries(Object.entries(font).map(([k,v])=>([k,
parseInt(v.join('').padEnd(sym_a, '0'), 3).toString(36)
])))
}
function fold_font(font){
const width = new RegExp(`(.{${sym_w}})`)
return Object.fromEntries(Object.entries(font).map(([k,v])=>([k,
v.join('').padEnd(sym_a, '0').split(width).slice(1,-1).join('\n')
])))
}
const fonts_decode = {}
fonts_decode.block36 = (s)=>parseInt(s, 36).toString(3).padStart(sym_a, '0').split('').map(s=>parseInt(s))
fonts_decode.blockString = (s)=>s.replace(/\s/g, '').padEnd(sym_a, '0').split('').map(s=>parseInt(s))
// const block36 = encode_font(fonts.block)
let fonts = {
blockString: {
"0": `
11111
10001
10201
10001
11111
`,
"1": `
01100
00100
00100
00100
00100
`,
"2": `
11111
00001
11111
10000
11111
`,
"3": `
11111
00001
01111
00001
11111
`,
"4": `
10001
10001
11111
00001
00001
`,
"5": `
11111
10000
11111
00001
11111
`,
"6": `
11111
10000
11111
10001
11111
`,
"7": `
11111
00001
00001
00001
00001
`,
"8": `
11111
10001
11111
10001
11111
`,
"9": `
11111
10001
11111
00001
00001
`,
"missing": `
22222
22202
20202
20222
22222
`,
" ": `
00000
00000
00000
00000
00000
`,
"A": `
11111
10001
11111
10001
10001
`,
"B": `
11110
10010
11111
10001
11111
`,
"C": `
11111
10001
10000
10001
11111
`,
"D": `
11110
10011
10001
10011
11110
`,
"E": `
11111
10000
11110
10000
11111
`,
"F": `
11111
10000
11110
10000
10000
`,
"G": `
11111
10000
10111
10001
11111
`,
"H": `
10001
10001
11111
10001
10001
`,
"I": `
11111
00100
00100
00100
11111
`,
"J": `
00001
00001
00001
10001
11111
`,
"K": `
10010
10010
11111
10001
10001
`,
"L": `
10000
10000
10000
10000
11111
`,
"M": `
11111
10101
10101
10101
10101
`,
"N": `
11111
10001
10001
10001
10001
`,
"O": `
11111
10001
10001
10001
11111
`,
"P": `
11111
10001
11111
10000
10000
`,
"Q": `
11110
10010
10010
10010
11111
`,
"R": `
11111
10001
11111
10010
10011
`,
"S": `
11111
10000
11111
00001
11111
`,
"T": `
11111
00100
00100
00100
00100
`,
"U": `
10001
10001
10001
10001
11111
`,
"V": `
10001
10001
11011
01110
00100
`,
"W": `
10101
10101
10101
10101
11111
`,
"X": `
10001
11011
01110
11011
10001
`,
"Y": `
10001
10001
11111
00100
00100
`,
"Z": `
11111
00011
01110
11000
11111
`,
"%": `
10001
00010
00100
01000
10001
`,
"-": `
00000
00000
01110
00000
00000
`,
".": `
00000
00000
00000
00000
10000
`,
":": `
00000
00100
00000
00100
00000
`,
"_": `
00000
00000
00000
00000
11111
`,
"🔋": `
01110
11111
10001
10001
11111
`,
"█": `
11111
11111
11111
11111
11111`
},
}
for(f in fonts){
const decode = fonts_decode[f]
if(!decode) continue
const font = fonts[f]
for(char in font){
font[char] = decode(font[char])
}
}
function setTheme(theme){
palettes = themes[theme]
can.style.backgroundColor = palettes.background
document.querySelector(`#theme [value=${theme}]`).selected = true
synchronize()
}
function str(s, x, y, m = 1, p = palettes._body, f = font, ctx = c){
s = [...s] // unicode
for(var i = 0; i < s.length; ++i){
symbol(
s[i],
x + i,
y, m, p, f, ctx
)
}
}
function symbol(s, x, y, m, p, f, c = c){
const font = fonts[f]
const bmp = font[s] || font.missing || fonts.block.missing
const l = bmp.length
// palettes[p] || console.log('p', p, Object.keys(palettes).join())
for(var i = 0; i < l; ++i){
let b = bmp[i]
if(b === 0) continue
c.fillStyle = palettes[p][b]
c.fillRect(
m * (x * g + (i % sym_w)) + pad_h,
(y * g + m * floor(i / sym_w)) + pad_v,
m, m
)
}
}
// display at the start of each second
function synchronize(){
window.clearTimeout(window.synchronizeTimeout)
const offset = Number(offset_el.value)
// const offset = 0
const t = new Date(Date.now() + offset)
// const t = new Date(offset)
display(t)
const r = 1000 - (t % 1000)
// window.synchronizeTimeout = window.setTimeout(synchronize, r)
}
function zeropad2(s){
return ('0' + s).slice(-2)
}
function display(t){
const month = months[t.getMonth()]
// const month = t.toLocaleString(locale, { month: 'short' }).toUpperCase()
const weekday = t.toLocaleString(locale, { weekday: 'long' }).toUpperCase()
const hours = t.getHours()
const minutes = t.getMinutes()
const time = zeropad2(hours) + ':' + zeropad2(minutes)
const seconds = zeropad2(t.getSeconds())
const numdate =
t.getFullYear()+
'-'+
zeropad2(t.getMonth() + 1)+
'-'+
zeropad2(t.getDate())
c.clearRect(0, 0, width, height)
const tiles = tiles_h * tiles_v
for(var i = 0; i < tiles; ++i){
c.fillStyle = 'rgba('+
Array(3).fill(
((i+1) % 2) * floor(random() * 256)
).concat(.1).join()
+')'
c.fillRect(
i % tiles_h * g2,
floor(i / tiles_h) * g2,
sym_w2, sym_w2
)
}
let x = y = 0, m = 1
let chars
chars = Object.keys(fonts.blockString)
for(var i = 0; i < chars.length / slots_h; ++i){
str(
chars.slice(
i * slots_h,
(i+1) * slots_h
),
0,
y+i,
_,
_,
font
)
}
y += 4
str(month, 10, y)
str(weekday.slice(0,3)+'.', 16, y)
str(numdate, 0, y+=1, 2)
str(time, 0, y+=3, 4)
str(seconds, 3, y+=4, 4, '1')
str(weekday, 0, y+=5, 2, '2')
str(weekday, 0, y+=5, 2)
y += 4
const ms_day = 864e5
const ms_centiday = 864e3
const temperature = (t % ms_day) / ms_centiday
}
setTheme('Dark')
synchronize()
</script>