-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
342 lines (327 loc) · 10.3 KB
/
Copy pathscript.js
File metadata and controls
342 lines (327 loc) · 10.3 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
330
331
332
333
334
335
336
337
338
339
340
341
342
// === GLOBAL NAVIGATION HIGHLIGHT ===
(function highlightActiveNav() {
const navLinks = document.querySelectorAll("header nav ul li a");
navLinks.forEach((link) => {
if (window.location.pathname.endsWith(link.getAttribute("href"))) {
link.classList.add("active");
}
});
})();
// === STONE AGE INTERACTIVES ===
(function stoneAgeDemos() {
// Wheel Spin
const wheel = document.getElementById("stone-wheel");
if (wheel) {
let angle = 0,
dragging = false,
prevX = 0;
wheel.addEventListener("mousedown", (e) => {
dragging = true;
prevX = e.clientX;
});
document.addEventListener("mousemove", (e) => {
if (dragging) {
angle += (e.clientX - prevX) * 0.9;
wheel.style.transform = `rotate(${angle}deg)`;
prevX = e.clientX;
}
});
document.addEventListener("mouseup", () => (dragging = false));
// Touch support
wheel.addEventListener("touchstart", (e) => {
dragging = true;
prevX = e.touches[0].clientX;
});
document.addEventListener("touchmove", (e) => {
if (dragging && e.touches && e.touches[0]) {
angle += (e.touches[0].clientX - prevX) * 0.9;
wheel.style.transform = `rotate(${angle}deg)`;
prevX = e.touches[0].clientX;
}
});
document.addEventListener("touchend", () => (dragging = false));
}
// Cave Art Drawing
const cave = document.getElementById("cave-canvas");
if (cave) {
const ctx = cave.getContext("2d");
let drawing = false;
cave.addEventListener("mousedown", (e) => {
drawing = true;
ctx.beginPath();
ctx.moveTo(e.offsetX, e.offsetY);
});
cave.addEventListener("mousemove", (e) => {
if (drawing) {
ctx.lineTo(e.offsetX, e.offsetY);
ctx.strokeStyle = "#7e5e2e";
ctx.lineWidth = 3.5;
ctx.lineCap = "round";
ctx.stroke();
}
});
cave.addEventListener("mouseup", () => {
drawing = false;
});
cave.addEventListener("mouseleave", () => {
drawing = false;
});
// Touch
cave.addEventListener("touchstart", (e) => {
drawing = true;
const rect = cave.getBoundingClientRect();
ctx.beginPath();
ctx.moveTo(
e.touches[0].clientX - rect.left,
e.touches[0].clientY - rect.top,
);
});
cave.addEventListener("touchmove", (e) => {
if (drawing) {
const rect = cave.getBoundingClientRect();
ctx.lineTo(
e.touches[0].clientX - rect.left,
e.touches[0].clientY - rect.top,
);
ctx.strokeStyle = "#7e5e2e";
ctx.lineWidth = 3.5;
ctx.lineCap = "round";
ctx.stroke();
}
});
cave.addEventListener("touchend", () => {
drawing = false;
});
}
})();
// === ANCIENT CIVILIZATIONS INTERACTIVES ===
(function ancientDemos() {
// Pyramid Secret Chamber
const pyramid = document.getElementById("pyramid");
if (pyramid) {
const chamber = document.getElementById("chamber");
pyramid.addEventListener("click", () => {
chamber.setAttribute(
"opacity",
chamber.getAttribute("opacity") === "1" ? "0" : "1",
);
});
}
// Cuneiform Typing Simulator
const cuneiformInput = document.getElementById("cuneiform-input");
const cuneiformOutput = document.getElementById("cuneiform-output");
if (cuneiformInput && cuneiformOutput) {
// Map Latin to a fake cuneiform font (or just unicode blocks for demo)
cuneiformInput.addEventListener("input", () => {
let val = cuneiformInput.value;
cuneiformOutput.textContent = val.replace(/[A-Za-z]/g, (ch) =>
String.fromCharCode(
0x12000 + ((ch.toUpperCase().charCodeAt(0) - 65) % 80),
),
);
});
}
// Abacus (Simple Counter)
const abacusInc = document.getElementById("abacus-inc");
const abacusDec = document.getElementById("abacus-dec");
const abacusVal = document.getElementById("abacus-value");
if (abacusInc && abacusDec && abacusVal) {
let value = 0;
abacusInc.onclick = () => {
value++;
abacusVal.textContent = value;
};
abacusDec.onclick = () => {
value--;
abacusVal.textContent = value;
};
}
})();
// === INDUSTRIAL REVOLUTION INTERACTIVES ===
(function industrialDemos() {
// Steam Engine Whistle
const whistle = document.getElementById("whistle");
const steam = document.getElementById("steam");
if (whistle && steam) {
whistle.addEventListener("mousedown", () => {
steam.setAttribute("opacity", "0.9");
setTimeout(() => steam.setAttribute("opacity", "0"), 700);
});
whistle.addEventListener("touchstart", () => {
steam.setAttribute("opacity", "0.9");
setTimeout(() => steam.setAttribute("opacity", "0"), 700);
});
}
// Morse Code Tapper
const morseBtn = document.getElementById("morse-btn");
const morseOut = document.getElementById("morse-output");
if (morseBtn && morseOut) {
let code = "";
let timer = null;
morseBtn.addEventListener("mousedown", () => {
morseBtn.textContent = "•";
timer = setTimeout(() => {
morseBtn.textContent = "–";
code += "-";
}, 250);
});
morseBtn.addEventListener("mouseup", () => {
if (morseBtn.textContent === "•") code += ".";
morseBtn.textContent = "Tap";
clearTimeout(timer);
morseOut.textContent = code;
});
morseBtn.addEventListener("mouseleave", () => {
morseBtn.textContent = "Tap";
clearTimeout(timer);
});
document.getElementById("morse-clear")?.addEventListener("click", () => {
code = "";
morseOut.textContent = "";
});
}
// Spinning Jenny Animation
const jenny = document.getElementById("jenny");
if (jenny) {
let spinning = false;
jenny.addEventListener("click", () => {
if (!spinning) {
spinning = true;
jenny.style.transition =
"transform 2s cubic-bezier(.68,-0.55,.27,1.55)";
jenny.style.transform = "rotate(720deg)";
setTimeout(() => {
jenny.style.transition = "";
jenny.style.transform = "";
spinning = false;
}, 2000);
}
});
}
})();
// === DIGITAL ERA INTERACTIVES ===
(function digitalDemos() {
// Terminal Emulator
const termInput = document.getElementById("terminal-input");
const termOutput = document.getElementById("terminal-output");
if (termInput && termOutput) {
termInput.focus();
termInput.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
let val = termInput.value.trim().toLowerCase();
if (!val) return;
if (val === "hello") termOutput.innerHTML = "👋 Hello, human!";
else if (val === "who are you")
termOutput.innerHTML = "🤖 I am a digital assistant.";
else if (val === "history")
termOutput.innerHTML =
"Computers evolved from vacuum tubes to AI in less than a century!";
else if (val === "ascii")
termOutput.innerHTML = "<pre>01001000 01101001</pre>";
else termOutput.innerHTML = "Unknown command.";
termInput.value = "";
}
});
}
// Pixel Art Demo
const pixelCanvas = document.getElementById("pixel-canvas");
if (pixelCanvas) {
const ctx = pixelCanvas.getContext("2d");
let drawing = false;
pixelCanvas.addEventListener("mousedown", (e) => {
drawing = true;
draw(e);
});
pixelCanvas.addEventListener("mousemove", (e) => {
if (drawing) draw(e);
});
pixelCanvas.addEventListener("mouseup", () => {
drawing = false;
});
pixelCanvas.addEventListener("mouseleave", () => {
drawing = false;
});
function draw(e) {
const rect = pixelCanvas.getBoundingClientRect();
const x = Math.floor((e.clientX - rect.left) / 10) * 10;
const y = Math.floor((e.clientY - rect.top) / 10) * 10;
ctx.fillStyle = "#00c3ff";
ctx.fillRect(x, y, 10, 10);
}
}
// Turing Machine Demo (very simple)
const turingBtn = document.getElementById("turing-btn");
const turingTape = document.getElementById("turing-tape");
if (turingBtn && turingTape) {
let tape = [0, 0, 0, 0, 0],
pos = 2;
function renderTape() {
turingTape.innerHTML = tape
.map(
(v, i) =>
`<span style="padding:0.2em 0.5em;${i === pos ? "background:#00c3ff;color:#fff;" : ""}">${v}</span>`,
)
.join("");
}
renderTape();
turingBtn.onclick = () => {
tape[pos] = tape[pos] ? 0 : 1;
pos = (pos + 1) % tape.length;
renderTape();
};
}
})();
// === FUTURE INTERACTIVES ===
(function futureDemos() {
// Rocket Launch
const rocket = document.getElementById("rocket");
const flame = document.getElementById("flame");
if (rocket && flame) {
rocket.addEventListener("click", () => {
rocket.style.transition =
"transform 1.2s cubic-bezier(.68,-0.55,.27,1.55)";
flame.setAttribute("opacity", "1");
rocket.style.transform = "translateY(-60px) scale(1.2)";
setTimeout(() => {
flame.setAttribute("opacity", "0");
rocket.style.transform = "";
}, 1000);
});
}
// AI Chatbot (very simple)
const aiInput = document.getElementById("ai-input");
const aiOutput = document.getElementById("ai-output");
if (aiInput && aiOutput) {
aiInput.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
let val = aiInput.value.trim().toLowerCase();
if (!val) return;
if (val.includes("hello"))
aiOutput.innerHTML = "🤖 Hello from the future!";
else if (val.includes("ai"))
aiOutput.innerHTML =
"AI will augment human creativity, not replace it.";
else if (val.includes("space"))
aiOutput.innerHTML = "Mars is just the beginning!";
else aiOutput.innerHTML = "I'm learning more every day...";
aiInput.value = "";
}
});
}
// Quantum Bit Visualizer
const qbit = document.getElementById("qbit");
if (qbit) {
let state = 0;
qbit.addEventListener("click", () => {
state = (state + 1) % 3;
if (state === 0) qbit.textContent = "0";
else if (state === 1) qbit.textContent = "1";
else qbit.textContent = "ψ";
});
}
})();
// === GENERAL ===
// Keyboard accessibility for all interactive SVGs and demos
document.querySelectorAll("svg,canvas,button,input").forEach((el) => {
el.setAttribute("tabindex", 0);
});