-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzalgo_fader.js
396 lines (376 loc) · 14.3 KB
/
zalgo_fader.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
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
//zalgo html color fader by Brenly github.com/brenly
//I made this to teach myself javascript! I already knew other languages and wanted to branch out!
//most of the code is in a single function because i'm rusty! apologies!
// vertical fade doesn't work. the olors work but the zalgo compresses similar to the problem with early versions of the project possibly use text tag? other color methods?
var zalgo_up = [ /* up */
'\u030d', /* ̍ */
'\u030e', /* ̎ */
'\u0304', /* ̄ */
'\u0305', /* ̅ */
'\u033f', /* ̿ */
'\u0311', /* ̑ */
'\u0306', /* ̆ */
'\u0310', /* ̐ */
'\u0352', /* ͒ */
'\u0357', /* ͗ */
'\u0351', /* ͑ */
'\u0307', /* ̇ */
'\u0308', /* ̈ */
'\u030a', /* ̊ */
'\u0342', /* ͂ */
'\u0343', /* ̓ */
'\u0344', /* ̈́ */
'\u034a', /* ͊ */
'\u034b', /* ͋ */
'\u034c', /* ͌ */
'\u0303', /* ̃ */
'\u0302', /* ̂ */
'\u030c', /* ̌ */
'\u0350', /* ͐ */
'\u0300', /* ̀ */
'\u0301', /* ́ */
'\u030b', /* ̋ */
'\u030f', /* ̏ */
'\u0312', /* ̒ */
'\u0313', /* ̓ */
'\u0314', /* ̔ */
'\u033d', /* ̽ */
'\u0309', /* ̉ */
'\u0363', /* ͣ */
'\u0364', /* ͤ */
'\u0365', /* ͥ */
'\u0366', /* ͦ */
'\u0367', /* ͧ */
'\u0368', /* ͨ */
'\u0369', /* ͩ */
'\u036a', /* ͪ */
'\u036b', /* ͫ */
'\u036c', /* ͬ */
'\u036d', /* ͭ */
'\u036e', /* ͮ */
'\u036f', /* ͯ */
'\u033e', /* ̾ */
'\u035b', /* ͛ */
'\u0346', /* ͆ */
'\u031a' /* ̚ */
];
var zalgo_down = [ /* down */
'\u0316', /* ̖ */
'\u0317', /* ̗ */
'\u0318', /* ̘ */
'\u0319', /* ̙ */
'\u031c', /* ̜ */
'\u031d', /* ̝ */
'\u031e', /* ̞ */
'\u031f', /* ̟ */
'\u0320', /* ̠ */
'\u0324', /* ̤ */
'\u0325', /* ̥ */
'\u0326', /* ̦ */
'\u0329', /* ̩ */
'\u032a', /* ̪ */
'\u032b', /* ̫ */
'\u032c', /* ̬ */
'\u032d', /* ̭ */
'\u032e', /* ̮ */
'\u032f', /* ̯ */
'\u0330', /* ̰ */
'\u0331', /* ̱ */
'\u0332', /* ̲ */
'\u0333', /* ̳ */
'\u0339', /* ̹ */
'\u033a', /* ̺ */
'\u033b', /* ̻ */
'\u033c', /* ̼ */
'\u0345', /* ͅ */
'\u0347', /* ͇ */
'\u0348', /* ͈ */
'\u0349', /* ͉ */
'\u034d', /* ͍ */
'\u034e', /* ͎ */
'\u0353', /* ͓ */
'\u0354', /* ͔ */
'\u0355', /* ͕ */
'\u0356', /* ͖ */
'\u0359', /* ͙ */
'\u035a', /* ͚ */
'\u0323' /* ̣ */
];
var zalgo_mid = [ /* mid */
'\u0315', /* ̕ */
'\u031b', /* ̛ */
'\u0340', /* ̀ */
'\u0341', /* ́ */
'\u0358', /* ͘ */
'\u0321', /* ̡ */
'\u0322', /* ̢ */
'\u0327', /* ̧ */
'\u0328', /* ̨ */
'\u0334', /* ̴ */
'\u0335', /* ̵ */
'\u0336', /* ̶ */
'\u034f', /* ͏ */
'\u035c', /* ͜ */
'\u035d', /* ͝ */
'\u035e', /* ͞ */
'\u035f', /* ͟ */
'\u0360', /* ͠ */
'\u0362', /* ͢ */
'\u0338', /* ̸ */
'\u0337', /* ̷ */
'\u0361', /* ͡ */
'\u0489' /* ҉_ */
];
//typical javascript rand function
function rand(max) {
return Math.floor(Math.random() * max);
}
function custom_background_display () {
var custom_background_color = document.getElementById("custom_background_display").value;
console.log(custom_background_color);
document.getElementById("output_colorized").style.backgroundColor = custom_background_color;
}
/* OLD FUNCTION HEADER FOR SAFEKEEPING
function he_comes(iText, zalgo_opt_mini, zalgo_opt_normal, zalgo_up, zalgo_down, zalgo_mid, color1, color2, colormid) {*/
function he_comes() {
//obtain source text...
//possibly broken feature...
var iText = document.getElementById("iText").value;
var plain_output = '';
var colorized_output = '';
var html_output = '';
//these 3 lines wipe the output boxes with each new click
document.getElementById("output_zalgo").innerHTML = "";
document.getElementById("output_colorized").innerHTML = "";
document.getElementById("output_html").innerHTML = "";
//in future rewrites, write this to pass integers of maximums rather than just true/false values
var zalgo_opt_mini = document.getElementById("zalgo_opt_mini").checked;
var zalgo_opt_normal = document.getElementById("zalgo_opt_normal").checked;
var zalgo_opt_maxi = document.getElementById("zalgo_opt_maxi").checked;
var horizontal_fade = document.getElementById("horizontal_fade").checked;
var vertical_fade = document.getElementById("vertical_fade").checked;
var up_opt = document.getElementById("up_opt").checked;
var down_opt = document.getElementById("down_opt").checked;
var mid_opt = document.getElementById("mid_opt").checked;
var color1 = document.getElementById("color1").value;
var color2 = document.getElementById("color2").value;
//custom mid color yes/no?
var colormid = document.getElementById("colormid").checked;
var custom_middle_color_value = document.getElementById("custom_middle_color_value").value;
var char_temp;
var static_vertical_axis;
var rand_num_up;
var static_num_up;
var rand_num_mid;
var static_num_mid;
var rand_num_down;
var static_num_down;
var color1_array = [0, 0, 0];
var color2_array = [0, 0, 0];
var colorsteps_array = [0, 0, 0];
//console.log(color1);
//console.log(color2);
//convert hexadecimal to RGB 255 using parseInt library
color1_array[0] = parseInt(color1.substring(1, 3), 16);
color1_array[1] = parseInt(color1.substring(3, 5), 16);
color1_array[2] = parseInt(color1.substring(5, 7), 16);
color2_array[0] = parseInt(color2.substring(1, 3), 16);
color2_array[1] = parseInt(color2.substring(3, 5), 16);
color2_array[2] = parseInt(color2.substring(5, 7), 16);
//calculate the differences in RGB values. negative numbers are fine! it will just decrement rather than increment when doing the fade calc.
if (horizontal_fade == true) {
for (var i = 0; i < 3; i++) {
colorsteps_array[i] = color1_array[i] - color2_array[i];
//console.log(colorsteps_array);
colorsteps_array[i] = colorsteps_array[i] / iText.length;
//console.log(colorsteps_array);
}
}
//console.log(color1_array);
//console.log(color2_array);
//console.log(colorsteps_array);
//this is for vertical color fades. this was the easiest solution to just set a y axis maximum and fade according to that dimension regardless of the number of characters. i feel it creates cleaner results visually
if (zalgo_opt_mini == true) {
static_num_up = 4;
static_num_mid = 2;
static_num_down = 4;
static_vertical_axis = 5;
} else if (zalgo_opt_normal == true) {
static_num_up = 7;
static_num_mid = 3;
static_num_down = 7;
static_vertical_axis = 8;
} else //maxi
{
static_num_up = 19;
static_num_mid = 5;
static_num_down = 19;
static_vertical_axis = 20;
}
if (vertical_fade == true) {
for (var i = 0; i < 3; i++) {
colorsteps_array[i] = color1_array[i] - color2_array[i];
//console.log(colorsteps_array);
colorsteps_array[i] = colorsteps_array[i] / static_vertical_axis;
//console.log(colorsteps_array);
}
}
//a previous version of this code put each character as it was generated directly into the output boxes. this resulted in the zalgo text appearing compressed. the work around was to generate an output buffer string and pass the entire string to the display box at once.
for (var i = 0; i < iText.length; i++) {
if (vertical_fade == true) {
//refresh color1_array
var color1 = document.getElementById("color1").value;
//convert hexadecimal to RGB 255 using parseInt library
color1_array[0] = parseInt(color1.substring(1, 3), 16);
color1_array[1] = parseInt(color1.substring(3, 5), 16);
color1_array[2] = parseInt(color1.substring(5, 7), 16);
}
//random reroll for each step horizontally. to create variations
if (zalgo_opt_mini == true) {
rand_num_up = rand(4);
rand_num_mid = rand(2);
rand_num_down = rand(4);
} else if (zalgo_opt_normal == true) {
rand_num_up = rand(12) / 2 + 1;
rand_num_mid = rand(6) / 2;
rand_num_down = rand(12) / 2 + 1;
} else //maxi
{
rand_num_up = rand(64) / 4 + 3;
rand_num_mid = rand(16) / 4 + 1;
rand_num_down = rand(64) / 4 + 3;
}
if (horizontal_fade == true) {
//this was not writen as a loop on purpose.
colorized_output += '<span style="color:rgb(';
color1_array[0] -= colorsteps_array[0];
colorized_output += Math.round(color1_array[0]);
colorized_output += ", ";
color1_array[1] -= colorsteps_array[1];
colorized_output += Math.round(color1_array[1]);
colorized_output += ", ";
color1_array[2] -= colorsteps_array[2];
colorized_output += Math.round(color1_array[2]);
colorized_output += ');">';
}
//console.log(colormid);
if (vertical_fade == true) {
colorized_output += '<span style="color:rgb(';
colorized_output += Math.round(color1_array[0]);
colorized_output += ", ";
colorized_output += Math.round(color1_array[1]);
colorized_output += ", ";
colorized_output += Math.round(color1_array[2]);
colorized_output += ');">';
}
//CUSTOM PLAINTEXT
if (colormid == true) {
console.log("custom middle color launched!");
colorized_output += '<span style="color:';
colorized_output += custom_middle_color_value;
colorized_output += ';">';
}
//add normal plain character..
plain_output += iText.charAt(i);
colorized_output += iText.charAt(i);
if (colormid == true) {
colorized_output += "</span>";
}
if (vertical_fade == true) {
colorized_output += "</span>";
}
if (up_opt == true) {
if (vertical_fade == true){ //reset color 1 before beginning zalgo print loop...
var color1 = document.getElementById("color1").value;
color1_array[0] = parseInt(color1.substring(1, 3), 16);
color1_array[1] = parseInt(color1.substring(3, 5), 16);
color1_array[2] = parseInt(color1.substring(5, 7), 16);
}
for (var j = 0; j < rand_num_up; j++) {
if (vertical_fade == true) {
colorized_output += '<span style="color:rgb(';
color1_array[0] -= colorsteps_array[0];
colorized_output += Math.round(color1_array[0]);
colorized_output += ", ";
color1_array[1] -= colorsteps_array[1];
colorized_output += Math.round(color1_array[1]);
colorized_output += ", ";
color1_array[2] -= colorsteps_array[2];
colorized_output += Math.round(color1_array[2]);
colorized_output += ');">';
}
char_temp = zalgo_up[Math.floor(Math.random() * zalgo_up.length)];
plain_output += char_temp;
colorized_output += char_temp;
//console.log(char_temp);
if (vertical_fade == true) {
colorized_output += "</span>";
}
}
}
if (mid_opt == true) {
if (vertical_fade == true){ //reset color1 before beginning zalgo print loop...
var color1 = document.getElementById("color1").value;
color1_array[0] = parseInt(color1.substring(1, 3), 16);
color1_array[1] = parseInt(color1.substring(3, 5), 16);
color1_array[2] = parseInt(color1.substring(5, 7), 16);
}
for (var j = 0; j < rand_num_mid; j++) {
if (vertical_fade == true) {
colorized_output += '<span style="color:rgb(';
color1_array[0] -= colorsteps_array[0];
colorized_output += Math.round(color1_array[0]);
colorized_output += ", ";
color1_array[1] -= colorsteps_array[1];
colorized_output += Math.round(color1_array[1]);
colorized_output += ", ";
color1_array[2] -= colorsteps_array[2];
colorized_output += Math.round(color1_array[2]);
colorized_output += ');">';
}
char_temp = zalgo_mid[Math.floor(Math.random() * zalgo_mid.length)];
plain_output += char_temp;
colorized_output += char_temp;
if (vertical_fade == true) {
colorized_output += "</span>";
}
}
}
if (down_opt == true) {
if (vertical_fade == true){ //reset color1 before beginning zalgo print loop...
var color1 = document.getElementById("color1").value;
color1_array[0] = parseInt(color1.substring(1, 3), 16);
color1_array[1] = parseInt(color1.substring(3, 5), 16);
color1_array[2] = parseInt(color1.substring(5, 7), 16);
}
for (var j = 0; j < rand_num_down; j++) {
if (vertical_fade == true) {
colorized_output += '<span style="color:rgb(';
color1_array[0] -= colorsteps_array[0];
colorized_output += Math.round(color1_array[0]);
colorized_output += ", ";
color1_array[1] -= colorsteps_array[1];
colorized_output += Math.round(color1_array[1]);
colorized_output += ", ";
color1_array[2] -= colorsteps_array[2];
colorized_output += Math.round(color1_array[2]);
colorized_output += ');">';
}
char_temp = zalgo_down[Math.floor(Math.random() * zalgo_down.length)];
plain_output += char_temp;
colorized_output += char_temp;
if (vertical_fade == true) {
colorized_output += "</span>";
}
}
}
if (horizontal_fade == true) {
//console.log("horizontal fade code activate!");
colorized_output += "</span>";
}
}
document.getElementById("output_zalgo").insertAdjacentHTML('beforeend', plain_output);
document.getElementById("output_colorized").insertAdjacentHTML('beforeend', colorized_output);
document.getElementById("output_html").insertAdjacentHTML('beforeend', colorized_output);
return;
}