-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
234 lines (188 loc) · 7.21 KB
/
index.html
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
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
document.body.style.backgroundImage = "url('https://github.com/Byte-Cats/bytcts/blob/main/assets/bg.gif?raw=true')";
document.body.style.backgroundSize = "cover";
document.body.style.width = "100%";
document.body.style.height = "100%";
var byteCats = document.createElement('div');
/* slowly change shadow color */
var message = "Byte Cats";
var messageArray = message.split("");
var messageArrayLength = messageArray.length;
/* add each letter of byteCats message to the page one by one */
for (var i = 0; i < messageArrayLength; i++) {
var letter = document.createElement('span');
letter.innerHTML = messageArray[i];
/* slowly add each letter to the page */
anime({
targets: letter,
opacity: [0, 1],
easing: "easeInOutQuad",
duration: 1000,
delay: 1000 + 1000 * i
});
letter.style.display = "inline-block";
letter.style.position = "relative";
letter.style.top = "0px";
letter.style.left = "0px";
letter.style.transform = "rotate(0deg)";
letter.style.transition = "all 0.5s ease-in-out";
/* add a random color to each letter */
letter.style.color = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")";
byteCats.appendChild(letter);
}
byteCats.classList.add("m12");
byteCats.style.fontFamily = "Fira Code";
byteCats.style.fontSize = "4em";
byteCats.style.fontWeight = "500";
byteCats.style.textAlign = "center";
byteCats.style.top = "40%";
byteCats.style.left = "30%";
byteCats.style.position = "absolute";
/* set color to purple */
byteCats.style.color = "#9c27b0";
/* set gradient for shadow */
byteCats.style.textShadow = "0 0 0.5em #9c27b0, 0 0 20px #9c27b0, 0 0 30px #9c27b0, 0 0 40px #9c27b0, 0 0 50px #9c27b0, 0 0 60px #9c27b0, 0 0 70px #9c27b0";
/* make the text shadow more opaque */
byteCats.style.opacity = "0.7";
/* add the div to the body */
/* slowly change the text shadow gradient over time */
anime({
targets: byteCats,
textShadow: ["0 0 0.5em #9c27b0, 0 0 20px #9c27b0, 0 0 30px #9c27b0, 0 0 40px #9c27b0, 0 0 50px #9c27b0, 0 0 60px #9c27b0, 0 0 70px #9c27b0", "0 0 0.5em #9c27b0, 0 0 20px #9c27b0, 0 0 30px #9c27b0, 0 0 40px #9c27b0, 0 0 50px #9c27b0, 0 0 60px #9c27b0, 0 0 70px #9c27b0"],
easing: "easeInOutQuad",
duration: 1000,
delay: 1000 + 1000 * messageArrayLength
});
document.body.appendChild(byteCats);
/* animate byteCats but go back to center */
anime({
targets: byteCats,
translateX: 20,
rotate: '1turn',
direction: 'alternate',
loop: true,
easing: 'easeInOutSine',
/* add delay to animation */
delay: 10000,
/* make each letter wiggle */
complete: function(anim) {
anime({
targets: '.letter .m12',
rotate: '1turn',
direction: 'alternate',
easing: 'easeInOutSine',
loop: true,
delay: 1000
});
}
});
/* add image as cat: https://github.com/Byte-Cats/bytcts/blob/main/assets/cat.gif?raw=true */
var cat = document.createElement('img');
cat.src = "https://github.com/Byte-Cats/bytcts/blob/main/assets/cat.gif?raw=true";
/* mirror the image horizontally */
cat.style.transform = "scaleX(-1)";
/* set position to the bottom left */
cat.style.position = "absolute";
cat.style.bottom = "3.5em";
cat.style.left = "0";
/* set size */
cat.style.width = "10%";
cat.style.height = "10%";
var cat_left = parseInt(cat.style.left);
var cat_collide = false;
/* add the image to the body */
document.body.appendChild(cat);
/* stop cat from being dragged */
cat.addEventListener("dragstart", function(event) {
event.preventDefault();
});
/* if cat is clicked move it slightly more to the right each time*/
cat.addEventListener("click", function() {
if (cat_left < 899 && cat_collide == false) {
cat_left += 200;
}
if (cat_left > 899 ) {
cat_collide = true;
}
if (cat_collide == true) {
cat.style.transform = "scaleX(1)";
cat.style.scaleX = "1";
cat_left -= 200;
}
if (cat_left == 0) {
cat_collide = false;
}
/* anime slide to the right */
anime({
targets: cat,
translateX: cat_left + "%",
/*mirror the image */
easing: 'easeInOutSine',
duration: 800
});
});
/* space bar is pressed make cat backflip */
document.addEventListener("keydown", function(event) {
if (event.code == "Space") {
/* anime back-flip */
/* wiggle the cat once if clicked and stop */
anime({
targets: cat,
translateX: 20,
rotate: '1turn',
direction: 'alternate',
loop: false,
easing: 'easeInOutSine',
/* slowly animate mirror horizontally */
complete: function(anim) {
anime({
targets: cat,
scaleX: -1,
easing: 'easeInOutSine',
duration: 300
});
}
});
}
});
window.addEventListener("resize", function() {
var width = window.innerWidth;
var height = window.innerHeight;
cat.style.width = width / 10 + "px";
cat.style.height = height / 10 + "px";
});
/* message saying code is lyfe at bottom footer */
var footer = document.createElement('div');
footer.innerHTML = 'Code is lyfe';
/* footer should be centered and anchored always at the bottom of the page */
footer.style.position = 'fixed';
footer.style.bottom = '0';
footer.style.left = '0';
footer.style.right = '0';
footer.style.textAlign = 'center';
footer.style.color = '#9c27b0';
footer.style.fontFamily = 'Fira Code';
footer.style.fontSize = '1.5em';
footer.style.fontWeight = '900';
footer.style.textShadow = "0 0 0.5em #9c27b0, 0 0 20px #9c27b0, 0 0 30px #9c27b0, 0 0 40px #9c27b0, 0 0 50px #9c27b0, 0 0 60px #9c27b0, 0 0 70px #9c27b0";
footer.style.opacity = "0.5";
document.body.appendChild(footer);
footer.addEventListener("click", function() {
window.location.href = "https://github.com/byte-cats/bytcts"; });
/* make footer flicker and change colors over time */
var colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'black', 'white'];
var colorIndex = 0;
setInterval(function() {
footer.style.color = colors[colorIndex];
colorIndex = (colorIndex + 1) % colors.length;
}, 1500);
});
</script>
</head>
<body>
</body>
</html>