-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminal.js
62 lines (59 loc) · 2.16 KB
/
terminal.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
const terminalText = (words, colors) => {
let letterCount = 1;
let x = 1;
let waiting = false;
let target = document.getElementById("text");
let sizer = document.getElementById("sizer");
let longest = "";
for (let w of words) {
if (w.length > longest.length) longest = w;
}
sizer.textContent = longest + "_";
let terminal = document.getElementById("terminal");
let visible = true;
target.setAttribute("style", "color:" + colors[0])
window.setInterval(() => {
if (letterCount === 0 && waiting === false) {
waiting = true;
window.setTimeout(() => {
var usedColor = colors.shift();
colors.push(usedColor);
var usedWord = words.shift();
words.push(usedWord);
x = 1;
target.setAttribute("style", "color:" + colors[0])
letterCount += x;
waiting = false;
}, 1000)
} else if (letterCount === words[0].length + 1 && waiting === false) {
waiting = true;
window.setTimeout(() => {
x = -1;
letterCount += x;
waiting = false;
}, 1000)
} else if (waiting === false) {
if (x == 1) {
const letter = document.createTextNode(words[0].charAt(letterCount - 1));
target.insertBefore(letter, terminal);
letterCount++;
} else if (x == -1) {
const lastLetter = terminal.previousSibling;
if (lastLetter) {
target.removeChild(lastLetter);
letterCount--;
}
}
}
}, 120)
window.setInterval(() => {
if (visible === true) {
terminal.className = "terminal-underscore hidden"
visible = false;
} else {
terminal.className = "terminal-underscore"
visible = true;
}
}, 400)
}
terminalText(["Darby Game Development Club", "Making Games", "Made with Love."], ["#444", "#478cbf", "#e87d0d"]);