-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordclock.js
133 lines (125 loc) · 4.34 KB
/
wordclock.js
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
const LAYOUTS = Object.freeze({
"de_DE": {
letters: "ESKISTAFÜNFZEHNZWANZIGDREIVIERTELVORFUNKNACHHALBAELFÜNFEINSMTXZWEIDREIAUJVIERSECHSNLACHTSIEBENZWÖLFZEHNEUNKUHR",
hours: [
[94, 98], // ZWÖLF
[55, 58], // EINS
[62, 65], // ZWEI
[66, 69], // DREI
[73, 76], // VIER
[51, 54], // FÜNF
[77, 81], // SECHS
[88, 93], // SIEBEN
[84, 87], // ACHT
[102, 105], // NEUN
[99, 102], // ZEHN
[49, 51], // ELF
],
words: [
[0, 1], // ES
[3, 5], // IST
[7, 10], // FÜNF
[11, 14], // ZEHN
[26, 32], // VIERTEL
[15, 21], // ZWANZIG
[33, 35], // VOR
[40, 43], // NACH
[44, 47], // HALB
[55, 57], // EIN
[107, 109], // UHR
],
logic: {
0: { words: [0, 1, 10], hour: 0 },
5: { words: [0, 1, 2, 7], hour: 0 },
10: { words: [0, 1, 3, 7], hour: 0 },
15: { words: [0, 1, 4, 7], hour: 0 },
20: { words: [0, 1, 5, 7], hour: 0 },
25: { words: [0, 1, 2, 6, 8], hour: 1 },
30: { words: [0, 1, 8], hour: 1 },
35: { words: [0, 1, 2, 7, 8], hour: 1 },
40: { words: [0, 1, 5, 6], hour: 1 },
45: { words: [0, 1, 4, 6], hour: 1 },
50: { words: [0, 1, 3, 6], hour: 1 },
55: { words: [0, 1, 2, 6], hour: 1 },
// edgecase at 1:00 / 13:00 "ES IST EIN UHR"
60: { words: [0, 1, 9, 10], hour: null },
},
},
"en_US": {
letters: "ITKISGHALFETENYQUARTERDTWENTYFIVETOPASTEFOURFIVETWONINETHREETWELVEBELEVENONESSEVENWEIGHTITENSIXTIESTINEO'CLOCK",
hours: [
[60, 65], // TWELVE
[73, 75], // ONE
[48, 50], // TWO
[55, 59], // THREE
[40, 43], // FOUR
[44, 47], // FIVE
[92, 94], // SIX
[77, 81], // SEVEN
[83, 87], // EIGHT
[51, 54], // NINE
[89, 91], // TEN
[67, 72], // ELEVEN
],
words: [
[0, 1], // IT
[3, 4], // IS
[6, 9], // HALF
[11, 13], // TEN
[15, 21], // QUARTER
[23, 28], // TWENTY
[29, 32], // FIVE
[33, 34], // TO
[35, 38], // PAST
[103, 109], // O'CLOCK
],
logic: {
0: { words: [0, 1, 9], hour: 0 },
5: { words: [0, 1, 6, 8], hour: 0 },
10: { words: [0, 1, 3, 8], hour: 0 },
15: { words: [0, 1, 4, 8], hour: 0 },
20: { words: [0, 1, 5, 8], hour: 0 },
25: { words: [0, 1, 5, 6, 8], hour: 0 },
30: { words: [0, 1, 2, 8], hour: 0 },
35: { words: [0, 1, 5, 6, 7], hour: 1 },
40: { words: [0, 1, 5, 7], hour: 1 },
45: { words: [0, 1, 4, 7], hour: 1 },
50: { words: [0, 1, 3, 7], hour: 1 },
55: { words: [0, 1, 6, 7], hour: 1 },
},
},
});
function find_layout(lang) {
// return the layout for the given language, defaulting to english
if (lang in LAYOUTS)
return LAYOUTS[lang]
return LAYOUTS["en_US"]
}
function letters(h, m, lang) {
let result = Array(110).fill(0)
let layout = find_layout(lang);
function light_up(from, to) {
for (var i = from; i <= to; i++)
result[i] = 1
}
// minute of day rounded to the previous five minutes (2:48 -> 165)
let logic_minute = h * 60 + Math.floor(m / 5) * 5
// remove the hours if no edge case given (165 -> 45)
if (!(logic_minute in layout.logic))
logic_minute %= 60;
// light up words
layout.logic[logic_minute].words.forEach(function (word) {
light_up(...layout.words[word])
})
// light up hour
if (layout.logic[logic_minute] != null)
light_up(...layout.hours[(h + layout.logic[logic_minute].hour) % 12]);
return result
}
function corners(m) {
// corners show minutes
let result = Array(4).fill(0)
for (var i = 0; i < 4; i++)
result[i] = i < (m % 5) ? 1 : 0
return result
}