-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
67 lines (56 loc) · 2.03 KB
/
Copy pathindex.ts
File metadata and controls
67 lines (56 loc) · 2.03 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
/**
* INTERSTELLAR: THE WATCH PROTOCOL (Bun Edition)
* Simulating the "Broken" watch hand as a Serial Data Transmitter.
*/
type Signal = "DOT" | "DASH" | "SPACE";
// 1. THE PROTOCOL: Mapping Quantum Data to Morse
const MORSE_MAP: Record<string, string> = {
"0": "—————", "1": "•————", "2": "••———", "3": "•••——", "4": "••••—",
"5": "•••••", "6": "—••••", "7": "——•••", "8": "———••", "9": "————•",
".": "•—•—•—", ",": "——••——", " ": " "
};
// 2. THE HARDWARE: The hijacked watch
class HamiltonWatch {
async twitch(signal: Signal) {
const char = signal === "DOT" ? "•" : signal === "DASH" ? "—" : " ";
// Use Bun's stdout to write without a newline
await Bun.write(Bun.stdout, char);
// Physical delay: Dots are quick, Dashes are long
const ms = signal === "DOT" ? 200 : signal === "DASH" ? 500 : 300;
await Bun.sleep(ms);
}
}
// 3. THE TRANSMITTER: Cooper in the Tesseract
class Tesseract {
private signals: Signal[] = [];
constructor(private watch: HamiltonWatch) {}
encode(data: string) {
for (const char of data.toUpperCase()) {
const code = MORSE_MAP[char];
if (code) {
for (const bit of code) {
this.signals.push(bit === "•" ? "DOT" : "DASH");
}
this.signals.push("SPACE");
}
}
}
async startBroadcast() {
console.log("\x1b[36m%s\x1b[0m", "--- TESSERACT ACTIVE ---");
console.log("Broadcasting Quantum Data to Murph's Room...\n");
// The perpetual loop of the Tesseract
while (true) {
for (const signal of this.signals) {
await this.watch.twitch(signal);
}
await Bun.write(Bun.stdout, " [SIGNAL REPEAT] ");
await Bun.sleep(1000);
}
}
}
// 4. RUNNING THE SCRIPT
const gravityData = "5.22, 0.18, 9.81"; // The "Answer" to the Gravity Equation
const watch = new HamiltonWatch();
const cooper = new Tesseract(watch);
cooper.encode(gravityData);
cooper.startBroadcast();