forked from plaaosert/satanicbanana.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.js
More file actions
123 lines (93 loc) · 2.84 KB
/
switch.js
File metadata and controls
123 lines (93 loc) · 2.84 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
let switch_txt = document.getElementById('switch-content');
// Invoked to run a function that hides a transition then disposes of itself.
cvg = 0;
process = 0;
cnv = "";
intv = null;
cur_anim = 0;
removing = [];
animations = ["ocean", "ocean-alt", null];
names = ["@@ a normal ocean", "@@ waves... sort of an ocean", "@@ nothing."]
function switch_to_next() {
prev = animations[cur_anim];
cur_anim = (cur_anim + 1) % animations.length;
start_switch(prev, animations[cur_anim]);
document.getElementById("5").classList.remove(prev + "-ind");
document.getElementById("5").classList.add(animations[cur_anim] + "-ind");
origs["5"] = names[cur_anim];
}
function add_mutation(txt, coverage) {
for (i=0; i<txt.length; i++) {
ch = txt[i];
rnd_s = Math.random()
if (ch != "\n") {
if ((ch == " " && rnd_s <= coverage) || rnd_s <= coverage / 50) {
txt = txt.replace_at(i, coverage - Math.random() >= Math.random() ? "█" : alphabet[Math.floor(Math.random() * alphabet.length)]);
}
else if (coverage - Math.random() >= 1)
txt = txt.replace_at(i, "█");
}
}
return txt;
}
function remove_mutation(txt, coverage) {
for (i=0; i<txt.length; i++) {
ch = txt[i];
if (ch != "\n") {
if (ch != " " && Math.random() <= coverage) {
txt = txt.replace_at(i, " ");
}
else if (Math.random() <= (1 - coverage) / 250) {
txt = txt.replace_at(i, alphabet[Math.floor(Math.random() * alphabet.length)]);
}
}
}
return txt;
}
function init_empty_canvas() {
return (" ".repeat(210) + "\n").repeat(10);
}
function start_switch(id_old, id_new) {
clearInterval(intv);
cnv = init_empty_canvas();
removing.push(id_old);
intv = setInterval(function() { switch_main(id_old, id_new); }, 1000/60);
process = 0;
cvg = 0;
}
function switch_main(id_old, id_new) {
// lerp cvg to 100 very quickly, set to 0 again then lerp to 100 for removal slower
if (process == 0) {
cvg += (2.2 - cvg) * 0.05;
cnv = add_mutation(cnv, cvg);
if (cvg >= 2.1) {
if (id_new != null) {
// don't start another if it is already running
if (main_intervals[id_new] == null) {
document.getElementById(id_new).style.display = "inline";
start_funcs[id_new]();
}
}
for (var i=0; i<removing.length; i++) {
if (removing[i] != null) {
document.getElementById(removing[i]).style.display = "none";
clearInterval(main_intervals[removing[i]]);
main_intervals[removing[i]] = null;
}
}
removing = [];
cvg = 0;
process = 1;
}
}
else {
cvg += (2.2 - cvg) * 0.003;
cnv = remove_mutation(cnv, cvg);
if (cvg >= 1.2) {
clearInterval(intv);
}
}
switch_txt.textContent = cnv;
}
document.getElementById("ocean").style.display = "inline";
start_funcs["ocean"]();