-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversifying.js
More file actions
286 lines (269 loc) · 8.16 KB
/
versifying.js
File metadata and controls
286 lines (269 loc) · 8.16 KB
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
var hexameter_tables_orig = {1 : "isatthtppmosuroueeprprirrsridebsrpsfairitiiii dadidamdba aaa aab b b ",
2 : "dffbivvddiaaeuoeoacctlrtrnmttalaabanaa a a a b bi b ",
3 : "mtivmvrasiiniaielchbqrldoiiiiuoierio a ss s brmb b rb ",
4 : "ppmppccpcrrooraoroæonrounondcstmscdfiutaiaeuicrrbtbdcruaautuuumnnbnunnnattutntttn n t tbbtr brb bb ",
5 : "sspfctdipioiœreouodmgdimgrcennempmguriorioailaaranrtaa a aaa br b ",
6 : "mqctpspssuuealoreælærnalamptdttnavpeaaaue ae m m b rrb b dbr "}
var hexameter_tables_revised = {1 : "tiphambleugeosaaufrnsrprrrfbesretbieiaiiriadrd mdaaraaaeaa a e ee ",
2 : "fsdbvscstaiaeiiacetgmlnssolannlcttra aaairrt e aaaaeeeee ",
3 : "sfptdpppfeoauoauaeqrtimttlruiisieoauis t mn sst t tsttssttt ",
4 : "pppppmcpprrroroarræooronuæomrmtdssnmoiieutaaunttncrbrlsatduaurgtnuunbnaartnntntnna tt n ttnt sts tssts sts ",
5 : "tppvlfacseoreuægrimcærmdmidpulbieimeolienrnerraaraaanaa a a ee eee ",
6 : "dsqapmdnsuæueruiiærpæealrgvaedrvtara abaa a eema e eee "};
var pentameter_tables = {1 : "tapisittneremomruotdrprpirxrufrdispiiaioiatiac dbd ia aeaaaea e e e ",
2 : "ppcppccsprroreooiræænærnngosscdfsgnctcliiuliuaruccmofrbiduimmiaubunuaecnnuntnnrattnt ttan t s ntss ssstt ststtss ",
3 : "iavvdflaaucieiaarsrtnrecbmtaaabttrar aaaa aeee e ",
4 : "dppncsmsmoureruoialdofuplnloetaeeeiisnennrssgadrdtbttn avaaaarae a a ee eeee ",
5 : "natvsmmvmoliiceaiivibrirldhaiiioaiei s s ss e e ee "};
var english_tables = {1 : "wshdshfvfioaiaooeacrrsdrurikdso rlyteihr i _hdd d d bl e ae r ds e s d ",
2 : "wdfwvvwgloeaaoooioretrwwrfsddesssdtssss sse s ",
3 : "ffIffyIfIoo_ooo_o_rrsrrutrk__a___h_nmyyatsiooeo _hentw u meekh a_ e ne r v s i l ",
4 : "ftwwpwypcoaiiriirorklloleoneellmlldft___i_duiecsbsc crlahrea emlroi u ewn s _ g e o f ",
5 : "sdpcotdqctrlofiouuaeemfmcapradpeetrssmgansrr secs ie ste nl ss es s ",
6 : "mccocaeaoaeenllvlfnrrleoiwtyttyanlae aa re yn ii l s nn y "};
var version = "original";
var pentameter = false;
var jump_time = 200;
var write_time = 1000;
function generate_table_html(tables, n, wide)
{
var table = tables[n];
var html = [];
if (wide) {
html.push("<div class='table table11'>");
} else {
html.push("<div class='table table10'>");
}
html.push("<div class='subheader'>" + n + "</div>");
for (var i in table) {
var letter = table[i];
if (letter == " ") {
html.push("<div class='tablecell blankcell'></div>");
} else if (letter == "_") {
html.push("<div class='tablecell'> </div>");
} else {
html.push("<div class='tablecell'>" + letter + "</div>");
}
}
html.push("</div>");
return html.join("");
}
function display_tables()
{
var html = [];
if (version == "revised") {
if (pentameter) {
html.push("<div class='header'>The Versifying Tables for Pentameter</div>");
for (var i = 1; i <= 5; i++) {
html.push(generate_table_html(pentameter_tables, i, false));
}
} else {
html.push("<div class='header'>The Versifying Tables for Hexameter</div>");
for (var i = 1; i <= 6; i++) {
html.push(generate_table_html(hexameter_tables_revised, i, false));
}
}
} else if (version == "English") {
html.push("<div class='header'>The Versifying Tables</div>");
for (var i = 1; i <= 6; i++) {
html.push(generate_table_html(english_tables, i, false));
}
} else {
html.push("<div class='header'>The Versifying Tables</div>");
for (var i = 1; i <= 6; i++) {
html.push(generate_table_html(hexameter_tables_orig, i,
i != 5));
}
}
html = html.join("");
$("#table-area").html(html);
// Hack to get tables to wrap as the window size changes.
var max_height = 0;
$(".table").each(function (i, table) {
var height = $(table).height();
if (height > max_height) {
max_height = height;
}
});
$(".table").each(function (i, table) {
$(table).height(max_height + "px");
});
}
function change_version()
{
cancel_generation();
version = $("#select-version").val();
if (version == "revised") {
$("#select-type").prop("disabled", "")
.val("hexameter");
} else {
$("#select-type").prop("disabled", "true")
.val("hexameter");
pentameter = false;
}
$("#input").val("123456");
display_tables();
}
function change_type()
{
cancel_generation();
var type = $("#select-type").val();
pentameter = type == "pentameter";
if (pentameter) {
$("#input").val("12345");
} else {
$("#input").val("123456");
}
display_tables();
}
function change_speed()
{
var fast = $("#select-speed").prop("checked");
if (fast) {
jump_time = 20;
write_time = 100;
} else {
jump_time = 200;
write_time = 1000;
}
}
function demystify(tables)
{
var word_lists = {};
for (var n in tables) {
var table = tables[n];
var table_length = table.length;
var word_list = [];
for (var digit = 1; digit < 10; digit++) {
var word = "";
for (var i = digit - 1; i < table_length; i += 9) {
var letter = table[i];
if (letter == " ") {
break;
}
word += letter;
}
word_list.push(word);
}
word_lists[n] = word_list;
}
return word_lists;
}
function validate_input(digits)
{
if (pentameter) {
if (digits.length != 5) {
return false;
}
} else {
if (digits.length != 6) {
return false;
}
}
return /^[1-9]+$/.test(digits);
}
function generate_verse(tables, digits)
{
var word_list = [];
for (var i in digits) {
var digit = digits[i];
var table = tables[parseInt(i)+1];
var table_length = table.length;
var word = "";
for (var j = digit - 1; j < table_length; j += 9) {
var letter = table[j];
if (letter == " ") {
break;
}
word += letter;
}
word_list.push(word);
}
return word_list.join(" ");
}
var timer;
function generate_step(tables, digits, i, j, k)
{
i = parseInt(i);
j = parseInt(j);
k = parseInt(k);
var table_idx = i;
if (i >= digits.length) {
return;
}
var digit = parseInt(digits[i]);
var table = tables[i+1];
var table_length = table.length;
if (k == 0) {
k = digit + 1;
}
if (k < 9) {
var table_el = $($("#table-area").children(".table")[table_idx]);
var cell_el = $(table_el.children(".tablecell")[j]);
var old_color = cell_el.css("background-color");
cell_el.css("background-color", "blue");
window.setTimeout(function() {
cell_el.css("background-color", old_color);
}, jump_time);
timer = window.setTimeout(function() {
generate_step(tables, digits, i, j + 1, k + 1);
}, jump_time);
return;
}
if (j >= table_length) {
generate_step(tables, digits, i + 1, 0, 0);
return;
}
var letter = table[j];
var table_el = $($("#table-area").children(".table")[table_idx]);
var cell_el = $(table_el.children(".tablecell")[j]);
var old_color = cell_el.css("background-color");
cell_el.css("background-color", "red");
if (letter == "_") {
$("#output-area").append(" ");
} else {
$("#output-area").append(letter);
}
window.setTimeout(function() {
cell_el.css("background-color", old_color);
}, write_time);
timer = window.setTimeout(function() {
if (letter == " ") {
generate_step(tables, digits, i + 1, 0, 0);
} else {
generate_step(tables, digits, i, j + 1, 1);
}
}, write_time);
}
function cancel_generation()
{
if (timer) {
clearTimeout(timer);
}
}
function generate()
{
cancel_generation();
var tables;
if (version == "revised") {
if (pentameter) {
tables = pentameter_tables;
} else {
tables = hexameter_tables_revised;
}
} else if (version == "English") {
tables = english_tables;
} else {
tables = hexameter_tables_orig;
}
var digits = $("#input").val();
if (validate_input(digits)) {
$("#output-area").html("");
generate_step(tables, digits, 0, 0, 0);
} else {
$("#output-area").html("Invalid input!");
}
}
$(function () {
display_tables();
});