-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
329 lines (263 loc) · 9.02 KB
/
script.js
File metadata and controls
329 lines (263 loc) · 9.02 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
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
const FACTS = [
"Time runs slightly faster at higher altitudes.",
"A second is defined by vibrations of cesium atoms.",
"Clocks on satellites must be corrected daily.",
"Gravity slows time near massive objects.",
"The Moon is moving away from Earth each year.",
"Days were shorter when dinosaurs lived.",
"Earth’s rotation is gradually slowing.",
"Time zones were created for railways.",
"Leap seconds are added to keep clocks aligned.",
"No two atomic clocks tick exactly the same.",
"Light from the Sun takes about 8 minutes to reach Earth.",
"There are more stars in the universe than grains of sand on Earth.",
"Some galaxies have no clear shape.",
"A day on Venus is longer than its year.",
"Neutron stars can spin hundreds of times per second.",
"Space is not completely silent.",
"The Milky Way is slowly colliding with Andromeda.",
"Black holes can warp nearby time.",
"Most of the universe is invisible matter.",
"Astronauts grow slightly taller in space.",
"The first computer bug was an actual insect.",
"Modern CPUs contain billions of transistors.",
"Early computers had less power than calculators.",
"Binary uses only two states: on and off.",
"Programming languages age like spoken languages.",
"Floating point math can never be perfectly exact.",
"The internet was not designed for video.",
"Most software bugs are simple logic errors.",
"A single typo can crash a system.",
"Code readability often matters more than speed.",
"The first hard drive weighed over a ton.",
"Touchscreens existed before smartphones.",
"The mouse was invented in the 1960s.",
"Email is older than the web.",
"Wi-Fi came from a failed radio experiment.",
"The QWERTY layout was made to reduce jams.",
"Early screens used vacuum tubes.",
"The first webcams watched a coffee pot.",
"Cameras once required hours of exposure.",
"Storage used to be measured in kilobytes.",
"The first video game was made in 1958.",
"Early games had no save feature.",
"Some game worlds are larger than real cities.",
"AI enemies often cheat slightly.",
"Lag is often caused by distance, not speed.",
"Game physics are usually approximations.",
"Speedrunners exploit tiny timing errors.",
"Retro consoles had strict memory limits.",
"Textures are often reused invisibly.",
"Many game sounds are recorded from real objects.",
"Human reaction time is about 200 milliseconds.",
"Silence is never truly silent.",
"Your brain predicts the present.",
"Most decisions happen before awareness.",
"Memory changes each time it’s recalled.",
"Eyes have a blind spot you never notice.",
"Dreams usually last only seconds.",
"Your sense of time changes with focus.",
"The brain uses more power than a light bulb.",
"Thinking feels continuous but isn’t.",
"Nothing is perfectly still.",
"Every clock drifts.",
"Precision has limits.",
"Distance creates delay.",
"Light defines the speed limit.",
"Randomness appears in nature.",
"Measurements change outcomes.",
"Small errors accumulate.",
"Time cannot be paused.",
"Systems tend toward noise.",
];
const clock = document.getElementById("clock");
let lastTime = "";
let blocks = [];
let x = 0;
let y = 0;
let tx = 0;
let ty = 0;
function getTimeString() {
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes();
const is24h = true;
if (!is24h) {
hours = hours % 12 || 12;
}
return (
String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0")
);
}
const DIGITS = {
0: ["01110", "10001", "10001", "10001", "10001", "10001", "01110"],
1: ["00100", "01100", "00100", "00100", "00100", "00100", "01110"],
2: ["01110", "10001", "00001", "00010", "00100", "01000", "11111"],
3: ["01110", "10001", "00001", "00110", "00001", "10001", "01110"],
4: ["00010", "00110", "01010", "10010", "11111", "00010", "00010"],
5: ["11111", "10000", "11110", "00001", "00001", "10001", "01110"],
6: ["00110", "01000", "10000", "11110", "10001", "10001", "01110"],
7: ["11111", "00001", "00010", "00100", "01000", "01000", "01000"],
8: ["01110", "10001", "10001", "01110", "10001", "10001", "01110"],
9: ["01110", "10001", "10001", "01111", "00001", "00010", "01100"],
":": ["0", "1", "0", "0", "1", "0", "0"],
};
function renderTimeString(str) {
clock.innerHTML = "";
[...str].forEach((char, index) => {
const grid = document.createElement("div");
const isColon = char === ":";
grid.className = isColon ? "colon-grid" : "digit-grid";
let shouldAnimate = lastTime && lastTime[index] !== char;
if (shouldAnimate) {
grid.classList.add("enter");
}
DIGITS[char].forEach((row) => {
[...row].forEach((cell) => {
const block = document.createElement("div");
block.className = "block";
if (cell === "1") block.classList.add("on");
grid.appendChild(block);
block.dataset.x = 0;
block.dataset.y = 0;
});
});
clock.appendChild(grid);
if (shouldAnimate) {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
grid.classList.remove("enter");
});
});
}
});
}
function updateClock() {
const currentTime = getTimeString();
if (currentTime !== lastTime) {
renderTimeString(currentTime);
lastTime = currentTime;
collectBlocks();
}
}
updateClock();
setInterval(updateClock, 1000);
collectBlocks();
applyGravity();
let lastFactIndex = -1;
function showRandomFact() {
let index;
do {
index = Math.floor(Math.random() * FACTS.length);
} while (index === lastFactIndex);
lastFactIndex = index;
fact.classList.add("fade-out");
setTimeout(() => {
fact.textContent = FACTS[index];
fact.classList.remove("fade-out");
}, 400);
}
showRandomFact();
setInterval(showRandomFact, 1 * 60 * 1000);
const cursor = document.getElementById("cursor");
document.addEventListener("mousemove", (e) => {
tx = e.clientX;
ty = e.clientY;
});
document.addEventListener(
"touchstart",
(e) => {
if (e.touches.length > 0) {
tx = e.touches[0].clientX;
ty = e.touches[0].clientY;
}
},
{ passive: true }
);
document.addEventListener(
"touchmove",
(e) => {
if (e.touches.length > 0) {
e.preventDefault();
tx = e.touches[0].clientX;
ty = e.touches[0].clientY;
}
},
{ passive: false }
);
function animateCursor() {
x += (tx - x) * 0.15;
y += (ty - y) * 0.15;
cursor.style.transform = `translate(${x - 4}px, ${y - 4}px)`;
requestAnimationFrame(animateCursor);
}
animateCursor();
function collectBlocks() {
blocks = Array.from(document.querySelectorAll(".block.on")).map((b) => {
const rect = b.getBoundingClientRect();
return {
el: b,
homeX: rect.left + rect.width / 2,
homeY: rect.top + rect.height / 2,
x: 0,
y: 0,
};
});
}
function applyGravity() {
const RADIUS = 120;
const STRENGTH = 12;
const RETURN = 0.08;
blocks.forEach((b) => {
const dx = tx - b.homeX;
const dy = ty - b.homeY;
const dist = Math.sqrt(dx * dx + dy * dy);
let targetX = 0;
let targetY = 0;
if (dist < RADIUS && dist > 0.001) {
const force = 1 - dist / RADIUS;
const nx = dx / dist;
const ny = dy / dist;
const px = -ny;
const py = nx;
const pull = force * 240;
const bend = force * 180 * Math.pow(force, 0.6);
targetX = nx * pull + px * bend;
targetY = ny * pull + py * bend;
const MAX_OFFSET = 55;
targetX = Math.max(-MAX_OFFSET, Math.min(MAX_OFFSET, targetX));
targetY = Math.max(-MAX_OFFSET, Math.min(MAX_OFFSET, targetY));
}
const relax = dist < RADIUS ? RETURN : RETURN * 0.6;
b.x += (targetX - b.x) * relax;
b.y += (targetY - b.y) * relax;
b.el.style.transform = `translate(${b.x}px, ${b.y}px)`;
});
requestAnimationFrame(applyGravity);
}
let wakeLock = null;
async function requestWakeLock() {
try {
wakeLock = await navigator.wakeLock.request("screen");
} catch (err) {
}
}
function requestFullscreen() {
const el = document.documentElement;
if (el.requestFullscreen) el.requestFullscreen();
else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen();
}
const hint = document.getElementById("hint");
function enterAmbientMode() {
requestFullscreen();
requestWakeLock();
hint.remove();
document.removeEventListener("click", enterAmbientMode);
document.removeEventListener("touchstart", enterAmbientMode);
}
document.addEventListener("click", enterAmbientMode, { once: true });
document.addEventListener("touchstart", enterAmbientMode, { once: true });
if ("ontouchstart" in window || navigator.maxTouchPoints > 0) {
const cursor = document.getElementById("cursor");
if (cursor) cursor.style.display = "none";
}