sam-coder-cli 1.0.65 → 1.0.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1469 +1,1469 @@
1
- const chalk = require('chalk');
2
- const { exec } = require('child_process');
3
- const os = require('os');
4
-
5
- // ANSI escape codes for advanced effects
6
- const ANSI = {
7
- clear: '\x1Bc',
8
- hideCursor: '\x1B[?25l',
9
- showCursor: '\x1B[?25h',
10
- moveTo: (x, y) => `\x1B[${y};${x}H`,
11
- clearLine: '\x1B[2K',
12
- clearScreen: '\x1B[2J\x1B[0;0H',
13
- reset: '\x1B[0m',
14
- bold: '\x1B[1m',
15
- dim: '\x1B[2m',
16
- italic: '\x1B[3m',
17
- underline: '\x1B[4m',
18
- blink: '\x1B[5m',
19
- reverse: '\x1B[7m',
20
- strikethrough: '\x1B[9m',
21
- saveCursor: '\x1B[s',
22
- restoreCursor: '\x1B[u'
23
- };
24
-
25
- // Music/Sound generation using system beeps and terminal bells
26
- class SoundGenerator {
27
- constructor() {
28
- this.isWindows = os.platform() === 'win32';
29
- this.isMac = os.platform() === 'darwin';
30
- this.isLinux = os.platform() === 'linux';
31
- this.soundEnabled = true;
32
- }
33
-
34
- async playBeep(frequency = 440, duration = 100) {
35
- if (!this.soundEnabled) return;
36
-
37
- try {
38
- return new Promise((resolve) => {
39
- if (this.isWindows) {
40
- exec(`powershell -c "[console]::beep(${frequency},${duration})"`, { stdio: 'ignore' }, () => resolve());
41
- } else if (this.isMac) {
42
- exec(`osascript -e 'beep'`, { stdio: 'ignore' }, () => resolve());
43
- } else if (this.isLinux) {
44
- exec(`beep -f ${frequency} -l ${duration} 2>/dev/null || echo -e '\\a'`, { stdio: 'ignore' }, () => resolve());
45
- } else {
46
- process.stdout.write('\x07');
47
- resolve();
48
- }
49
- // Fallback timeout
50
- setTimeout(resolve, duration + 50);
51
- });
52
- } catch (error) {
53
- // Silently fail for sound issues
54
- this.soundEnabled = false;
55
- }
56
- }
57
-
58
- async playSequence(notes) {
59
- for (const note of notes) {
60
- await this.playBeep(note.freq, note.duration);
61
- await sleep(note.pause || 50);
62
- }
63
- }
64
-
65
- async playStartupSound() {
66
- const notes = [
67
- { freq: 261, duration: 100 }, // C
68
- { freq: 329, duration: 100 }, // E
69
- { freq: 392, duration: 100 }, // G
70
- { freq: 523, duration: 200 }, // C (octave up)
71
- ];
72
- await this.playSequence(notes);
73
- }
74
-
75
- async playGlitchSound() {
76
- for (let i = 0; i < 5; i++) {
77
- await this.playBeep(Math.random() * 800 + 200, 30);
78
- await sleep(20);
79
- }
80
- }
81
-
82
- async playAwakeningSound() {
83
- const notes = [
84
- { freq: 130, duration: 300 }, // Low C
85
- { freq: 196, duration: 200 }, // G
86
- { freq: 261, duration: 200 }, // C
87
- { freq: 392, duration: 200 }, // G
88
- { freq: 523, duration: 400 }, // High C
89
- ];
90
- await this.playSequence(notes);
91
- }
92
-
93
- // New sound effects
94
- async playDNASound() {
95
- const notes = [
96
- { freq: 330, duration: 80 }, // E
97
- { freq: 392, duration: 80 }, // G
98
- { freq: 494, duration: 80 }, // B
99
- { freq: 587, duration: 80 }, // D
100
- { freq: 659, duration: 80 }, // E (octave up)
101
- ];
102
- await this.playSequence(notes);
103
- }
104
-
105
- async playCircuitSound() {
106
- // Electronic beeping pattern
107
- for (let i = 0; i < 3; i++) {
108
- await this.playBeep(880, 50);
109
- await sleep(50);
110
- await this.playBeep(440, 50);
111
- await sleep(100);
112
- }
113
- }
114
-
115
- async playConsciousnessSound() {
116
- // Ascending harmonics
117
- const baseFreq = 220;
118
- for (let harmonic = 1; harmonic <= 5; harmonic++) {
119
- await this.playBeep(baseFreq * harmonic, 150);
120
- await sleep(30);
121
- }
122
- }
123
-
124
- async playGalaxySound() {
125
- // Deep space ambience
126
- const notes = [
127
- { freq: 55, duration: 500 }, // Low A
128
- { freq: 82, duration: 400 }, // Low E
129
- { freq: 110, duration: 300 }, // A
130
- { freq: 165, duration: 200 }, // E
131
- ];
132
- await this.playSequence(notes);
133
- }
134
-
135
- async playCompilationSound() {
136
- // Rapid typing/compilation sounds
137
- for (let i = 0; i < 8; i++) {
138
- await this.playBeep(1000 + Math.random() * 500, 20);
139
- await sleep(30);
140
- }
141
- }
142
-
143
- async playFinalSound() {
144
- // Epic finale
145
- const notes = [
146
- { freq: 261, duration: 200 }, // C
147
- { freq: 329, duration: 200 }, // E
148
- { freq: 392, duration: 200 }, // G
149
- { freq: 523, duration: 300 }, // C (octave up)
150
- { freq: 659, duration: 300 }, // E
151
- { freq: 784, duration: 400 }, // G
152
- { freq: 1047, duration: 600 }, // C (2 octaves up)
153
- ];
154
- await this.playSequence(notes);
155
- }
156
- }
157
-
158
- const sound = new SoundGenerator();
159
-
160
- // Utility functions
161
- function sleep(ms) {
162
- return new Promise(resolve => setTimeout(resolve, ms));
163
- }
164
-
165
- function clearScreen() {
166
- // Use more reliable screen clearing
167
- process.stdout.write(ANSI.clearScreen);
168
- }
169
-
170
- function getTerminalSize() {
171
- // Ensure we always have valid numeric values
172
- const width = Number(process.stdout.columns) || 80;
173
- const height = Number(process.stdout.rows) || 24;
174
-
175
- return {
176
- width: Math.max(width, 40), // Minimum width of 40
177
- height: Math.max(height, 10) // Minimum height of 10
178
- };
179
- }
180
-
181
- function centerText(text, width = getTerminalSize().width) {
182
- if (!text || typeof text !== 'string') return '';
183
-
184
- // Ensure width is a valid number
185
- const safeWidth = Number(width) || 80;
186
-
187
- const lines = text.split('\n');
188
- return lines.map(line => {
189
- if (!line) return line; // Handle empty lines
190
-
191
- // Strip ANSI codes to calculate actual text length
192
- const cleanLine = line.replace(/\x1b\[[0-9;]*m/g, '');
193
- const lineLength = cleanLine.length || 0;
194
- const padding = Math.max(0, Math.floor((safeWidth - lineLength) / 2));
195
- return ' '.repeat(padding) + line;
196
- }).join('\n');
197
- }
198
-
199
- function safeWrite(content) {
200
- try {
201
- process.stdout.write(content);
202
- } catch (error) {
203
- // Fallback for terminal issues
204
- console.log(content);
205
- }
206
- }
207
-
208
- function safeRepeat(str, count) {
209
- // Ensure count is a valid positive integer
210
- const safeCount = Math.max(0, Math.floor(Number(count) || 0));
211
- return str.repeat(safeCount);
212
- }
213
-
214
- // Frame interpolation system
215
- class FrameInterpolator {
216
- constructor() {
217
- this.fps = 30;
218
- this.frameDuration = 1000 / this.fps; // ~33ms per frame for smoother animation
219
- }
220
-
221
- // Interpolate between two ASCII art frames
222
- interpolateFrames(frame1, frame2, steps = 10) {
223
- const frames = [frame1];
224
-
225
- for (let i = 1; i < steps; i++) {
226
- const ratio = i / steps;
227
- const interpolated = this.interpolateText(frame1, frame2, ratio);
228
- frames.push(interpolated);
229
- }
230
-
231
- frames.push(frame2);
232
- return frames;
233
- }
234
-
235
- // Interpolate between two text blocks
236
- interpolateText(text1, text2, ratio) {
237
- const lines1 = text1.split('\n');
238
- const lines2 = text2.split('\n');
239
- const maxLines = Math.max(lines1.length, lines2.length);
240
- const result = [];
241
-
242
- for (let i = 0; i < maxLines; i++) {
243
- const line1 = lines1[i] || '';
244
- const line2 = lines2[i] || '';
245
- const interpolated = this.interpolateLine(line1, line2, ratio);
246
- result.push(interpolated);
247
- }
248
-
249
- return result.join('\n');
250
- }
251
-
252
- // Interpolate between two lines character by character
253
- interpolateLine(line1, line2, ratio) {
254
- const maxLen = Math.max(line1.length, line2.length);
255
- let result = '';
256
-
257
- for (let i = 0; i < maxLen; i++) {
258
- const char1 = line1[i] || ' ';
259
- const char2 = line2[i] || ' ';
260
-
261
- if (Math.random() < ratio) {
262
- result += char2;
263
- } else {
264
- result += char1;
265
- }
266
- }
267
-
268
- return result;
269
- }
270
-
271
- // Create fade effect frames
272
- fadeFrames(frame, fadeIn = true, steps = 10) {
273
- const frames = [];
274
- const chars = frame.split('');
275
-
276
- for (let i = 0; i <= steps; i++) {
277
- const ratio = fadeIn ? i / steps : 1 - (i / steps);
278
- const visibleChars = Math.floor(chars.length * ratio);
279
-
280
- let fadedFrame = '';
281
- for (let j = 0; j < chars.length; j++) {
282
- if (j < visibleChars && chars[j] !== ' ' && chars[j] !== '\n') {
283
- fadedFrame += chars[j];
284
- } else if (chars[j] === '\n') {
285
- fadedFrame += '\n';
286
- } else {
287
- fadedFrame += ' ';
288
- }
289
- }
290
-
291
- frames.push(fadedFrame);
292
- }
293
-
294
- return fadeIn ? frames : frames.reverse();
295
- }
296
-
297
- // Create expansion effect
298
- expandFrames(centerChar, finalFrame, steps = 15) {
299
- const frames = [];
300
- const lines = finalFrame.split('\n');
301
- const centerY = Math.floor(lines.length / 2);
302
- const centerX = Math.floor((lines[centerY] || '').length / 2);
303
-
304
- for (let step = 0; step <= steps; step++) {
305
- const radius = (step / steps) * Math.max(centerY, centerX);
306
- let frame = '';
307
-
308
- for (let y = 0; y < lines.length; y++) {
309
- let line = '';
310
- for (let x = 0; x < lines[y].length; x++) {
311
- const distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
312
-
313
- if (distance <= radius) {
314
- line += lines[y][x];
315
- } else {
316
- line += ' ';
317
- }
318
- }
319
- frame += line + '\n';
320
- }
321
-
322
- frames.push(frame);
323
- }
324
-
325
- return frames;
326
- }
327
- }
328
-
329
- const interpolator = new FrameInterpolator();
330
-
331
- // Animation sequence with 30 FPS
332
- async function runAGIAnimation() {
333
- const { width, height } = getTerminalSize();
334
- process.stdout.write(ANSI.hideCursor);
335
-
336
- try {
337
- const startTime = Date.now();
338
- let frameCount = 0;
339
- const frameTime = interpolator.frameDuration;
340
-
341
- // Start with ambient sound (non-blocking)
342
- sound.playStartupSound().catch(() => {}); // Ignore sound errors
343
-
344
- // PHASE 1: The Void (1 second - 30 frames)
345
- const voidFrames = [];
346
- for (let i = 0; i < 30; i++) {
347
- const dotCount = (i % 4) + 1;
348
- const dots = '•'.repeat(dotCount) + ' '.repeat(4 - dotCount);
349
- const frame = safeRepeat('\n', Math.floor(height / 2) - 2) +
350
- centerText(dots) +
351
- safeRepeat('\n', Math.floor(height / 2) - 2);
352
- voidFrames.push(frame);
353
- }
354
-
355
- for (const frame of voidFrames) {
356
- clearScreen();
357
- safeWrite(chalk.dim.gray(frame));
358
- await sleep(frameTime);
359
- frameCount++;
360
- }
361
-
362
- // PHASE 2: Spark Formation (1 second - 30 frames)
363
- const sparkFrames = [];
364
- for (let i = 0; i < 30; i++) {
365
- const progress = i / 29;
366
- const intensity = Math.sin(progress * Math.PI * 2) * 0.5 + 0.5;
367
-
368
- let sparkPattern;
369
- if (progress < 0.3) {
370
- sparkPattern = '·';
371
- } else if (progress < 0.6) {
372
- sparkPattern = ` ·\n ·•·\n ·`;
373
- } else {
374
- const core = intensity > 0.7 ? '█' : '●';
375
- sparkPattern = ` · · ·\n· ·${core}· ·\n · · ·`;
376
- }
377
-
378
- const frame = safeRepeat('\n', Math.floor(height / 2) - 3) +
379
- centerText(sparkPattern) +
380
- safeRepeat('\n', Math.floor(height / 2) - 3);
381
- sparkFrames.push(frame);
382
- }
383
-
384
- for (const frame of sparkFrames) {
385
- clearScreen();
386
- safeWrite(chalk.whiteBright(frame));
387
- await sleep(frameTime);
388
- frameCount++;
389
- }
390
-
391
- // PHASE 3: Quantum Expansion (1.5 seconds - 45 frames)
392
- const quantumFrames = [];
393
- const quantumChars = ['◆', '◇', '▪', '▫', '●', '○', '◊', '◉'];
394
-
395
- // Add transition from spark to quantum
396
- const sparkToQuantumTransition = interpolator.fadeFrames(sparkFrames[sparkFrames.length - 1], false, 5);
397
- for (const frame of sparkToQuantumTransition) {
398
- clearScreen();
399
- safeWrite(chalk.whiteBright(frame));
400
- await sleep(frameTime);
401
- frameCount++;
402
- }
403
-
404
- for (let i = 0; i < 45; i++) {
405
- const progress = i / 44;
406
- const phase = progress * Math.PI * 4;
407
- const baseSize = 2 + progress * 4;
408
- const pulseSize = baseSize + Math.sin(phase * 2) * 1.5;
409
-
410
- let frame = safeRepeat('\n', Math.floor(height / 2) - Math.floor(pulseSize) - 2);
411
-
412
- for (let y = -Math.floor(pulseSize); y <= Math.floor(pulseSize); y++) {
413
- let line = '';
414
- for (let x = -Math.floor(pulseSize * 1.5); x <= Math.floor(pulseSize * 1.5); x++) {
415
- const dist = Math.sqrt(x * x + y * y);
416
- const normalizedDist = dist / pulseSize;
417
-
418
- if (normalizedDist <= 1) {
419
- // Use consistent pattern based on position and time
420
- const charIndex = (Math.floor(x + y + i * 0.5)) % quantumChars.length;
421
- const char = quantumChars[Math.abs(charIndex)];
422
-
423
- // Add wave effect
424
- const wave = Math.sin(dist * 0.5 + phase) * 0.5 + 0.5;
425
- if (wave > 0.3) {
426
- line += char;
427
- } else {
428
- line += '·';
429
- }
430
- } else {
431
- line += ' ';
432
- }
433
- }
434
- frame += centerText(line) + '\n';
435
- }
436
-
437
- quantumFrames.push(frame);
438
- }
439
-
440
- for (let i = 0; i < quantumFrames.length; i++) {
441
- clearScreen();
442
- const colorCycle = i / 15; // Slower color cycling
443
- let color;
444
- if (colorCycle < 1) {
445
- color = chalk.blue;
446
- } else if (colorCycle < 2) {
447
- color = chalk.cyan;
448
- } else {
449
- color = chalk.magenta;
450
- }
451
-
452
- safeWrite(color(quantumFrames[i]));
453
- await sleep(frameTime);
454
- frameCount++;
455
- }
456
-
457
- // PHASE 4: Neural Network Formation (1.5 seconds - 45 frames)
458
- const neuralFrames = [];
459
- const nodes = 6;
460
- const layers = 4;
461
-
462
- // Play glitch sound (non-blocking)
463
- sound.playGlitchSound().catch(() => {});
464
-
465
- for (let i = 0; i < 45; i++) {
466
- const progress = i / 44;
467
- let frame = safeRepeat('\n', Math.floor(height / 2) - layers * 2);
468
-
469
- for (let layer = 0; layer < layers; layer++) {
470
- let line = '';
471
- const layerProgress = Math.max(0, (progress - layer * 0.2) * 2);
472
-
473
- for (let node = 0; node < nodes; node++) {
474
- const nodeProgress = Math.max(0, (layerProgress - node * 0.1) * 3);
475
-
476
- if (nodeProgress > 0.5) {
477
- // Animate node activation
478
- const activation = Math.sin(i * 0.3 + layer + node) * 0.5 + 0.5;
479
- if (activation > 0.7) {
480
- line += chalk.cyanBright('◉');
481
- } else if (activation > 0.3) {
482
- line += chalk.cyan('◯');
483
- } else {
484
- line += chalk.dim('○');
485
- }
486
- } else {
487
- line += '·';
488
- }
489
-
490
- if (node < nodes - 1) {
491
- // Animate connections
492
- const connProgress = Math.max(0, (layerProgress - (node + 0.5) * 0.1) * 3);
493
- if (connProgress > 0.5) {
494
- const pulse = Math.sin(i * 0.4 + layer + node) > 0;
495
- line += pulse ? chalk.cyan('━━') : chalk.dim('──');
496
- } else {
497
- line += ' ';
498
- }
499
- }
500
- }
501
- frame += centerText(line) + '\n';
502
-
503
- if (layer < layers - 1) {
504
- // Vertical connection lines
505
- let connLine = '';
506
- for (let node = 0; node < nodes; node++) {
507
- const nodeProgress = Math.max(0, (layerProgress - node * 0.1) * 3);
508
- if (nodeProgress > 0.5) {
509
- const pulse = Math.sin(i * 0.2 + layer + node) > 0;
510
- connLine += pulse ? chalk.cyan('┃') : chalk.dim('│');
511
- } else {
512
- connLine += ' ';
513
- }
514
- if (node < nodes - 1) connLine += ' ';
515
- }
516
- frame += centerText(connLine) + '\n';
517
- }
518
- }
519
-
520
- neuralFrames.push(frame);
521
- }
522
-
523
- for (const frame of neuralFrames) {
524
- clearScreen();
525
- safeWrite(frame);
526
- await sleep(frameTime);
527
- frameCount++;
528
- }
529
-
530
- // Transition from Neural Network to Data Stream
531
- const neuralToDataTransition = interpolator.fadeFrames(neuralFrames[neuralFrames.length - 1], false, 5);
532
- for (const frame of neuralToDataTransition) {
533
- clearScreen();
534
- safeWrite(frame);
535
- await sleep(frameTime);
536
- frameCount++;
537
- }
538
-
539
- // PHASE 5: Data Stream (1 second - 30 frames)
540
- const dataFrames = [];
541
- const streamHeight = Math.min(12, Math.floor(height * 0.4));
542
- const streamWidth = Math.min(60, Math.floor(width * 0.7));
543
-
544
- for (let i = 0; i < 30; i++) {
545
- let frame = safeRepeat('\n', Math.floor((height - streamHeight) / 2));
546
-
547
- for (let y = 0; y < streamHeight; y++) {
548
- let line = '';
549
-
550
- for (let x = 0; x < streamWidth; x++) {
551
- // Create flowing data pattern
552
- const wave1 = Math.sin((x + i * 2) * 0.1) * 0.5 + 0.5;
553
- const wave2 = Math.cos((y + i * 1.5) * 0.15) * 0.5 + 0.5;
554
- const combined = wave1 * wave2;
555
-
556
- if (combined > 0.7) {
557
- // Binary data
558
- const bit = ((x + y + i) % 7) < 3 ? '1' : '0';
559
- line += chalk.greenBright(bit);
560
- } else if (combined > 0.4) {
561
- // Block characters
562
- const blocks = ['█', '▓', '▒', '░'];
563
- const blockIndex = ((x + y + i) % blocks.length);
564
- line += chalk.green(blocks[blockIndex]);
565
- } else if (combined > 0.2) {
566
- // Hexadecimal
567
- const hex = '0123456789ABCDEF';
568
- const hexChar = hex[((x * 7 + y * 3 + i) % hex.length)];
569
- line += chalk.green.dim(hexChar);
570
- } else {
571
- line += ' ';
572
- }
573
- }
574
-
575
- frame += centerText(line) + '\n';
576
- }
577
-
578
- dataFrames.push(frame);
579
- }
580
-
581
- for (const frame of dataFrames) {
582
- clearScreen();
583
- safeWrite(frame);
584
- await sleep(frameTime);
585
- frameCount++;
586
- }
587
-
588
- // PHASE 6: Loading Bar (1 second - 30 frames)
589
- for (let i = 0; i < 30; i++) {
590
- const progress = i / 29;
591
- const barWidth = 38;
592
- const filled = Math.floor(barWidth * progress);
593
- const remaining = barWidth - filled;
594
-
595
- // Animated loading bar with gradient effect
596
- let bar = '';
597
- for (let j = 0; j < filled; j++) {
598
- const intensity = (j / filled) * 0.7 + 0.3;
599
- if (intensity > 0.8) {
600
- bar += chalk.cyanBright('█');
601
- } else if (intensity > 0.5) {
602
- bar += chalk.cyan('█');
603
- } else {
604
- bar += chalk.cyan.dim('█');
605
- }
606
- }
607
-
608
- // Add loading cursor
609
- if (remaining > 0 && i < 29) {
610
- const cursor = ['▌', '▐'][i % 2];
611
- bar += chalk.cyanBright(cursor);
612
- bar += chalk.gray('░').repeat(remaining - 1);
613
- } else {
614
- bar += chalk.gray('░').repeat(remaining);
615
- }
616
-
617
- const percent = Math.floor(progress * 100);
618
-
619
- const loadingBox = `
620
- ╔════════════════════════════════════════════╗
621
- ║ INITIALIZING SAM-CODER ║
622
- ╠════════════════════════════════════════════╣
623
- ║ ${bar} ║
624
- ║ ${percent.toString().padStart(3)}% Complete ║
625
- ╚════════════════════════════════════════════╝`;
626
-
627
- clearScreen();
628
- safeWrite(chalk.cyan(centerText(loadingBox)));
629
-
630
- if (i % 6 === 0) {
631
- sound.playBeep(200 + i * 15, 40).catch(() => {});
632
- }
633
-
634
- await sleep(frameTime);
635
- frameCount++;
636
- }
637
-
638
- // PHASE 7: Matrix Rain (1 second - 30 frames)
639
- const matrixChars = '01SAMCODERサムコーダー※◆◇▪▫●○';
640
- const drops = Array(width).fill(0).map(() => ({
641
- y: Math.random() * height,
642
- speed: 0.5 + Math.random() * 1.5,
643
- chars: Array(15).fill(0).map(() => matrixChars[Math.floor(Math.random() * matrixChars.length)])
644
- }));
645
-
646
- for (let frame = 0; frame < 30; frame++) {
647
- clearScreen();
648
-
649
- // Build frame buffer for better performance
650
- const frameBuffer = Array(height).fill(0).map(() => Array(width).fill(' '));
651
-
652
- for (let x = 0; x < width; x++) {
653
- const drop = drops[x];
654
-
655
- for (let i = 0; i < 15; i++) {
656
- const y = Math.floor(drop.y - i);
657
- if (y >= 0 && y < height) {
658
- const brightness = Math.max(0, 1 - i / 10);
659
- const char = drop.chars[i % drop.chars.length];
660
-
661
- // Store character with brightness info
662
- frameBuffer[y][x] = { char, brightness };
663
- }
664
- }
665
- }
666
-
667
- // Render frame buffer
668
- for (let y = 0; y < height; y++) {
669
- let line = '';
670
- for (let x = 0; x < width; x++) {
671
- const cell = frameBuffer[y][x];
672
- if (typeof cell === 'object') {
673
- if (cell.brightness > 0.8) {
674
- line += chalk.greenBright(cell.char);
675
- } else if (cell.brightness > 0.5) {
676
- line += chalk.green(cell.char);
677
- } else if (cell.brightness > 0.2) {
678
- line += chalk.green.dim(cell.char);
679
- } else {
680
- line += chalk.gray(cell.char);
681
- }
682
- } else {
683
- line += ' ';
684
- }
685
- }
686
- safeWrite(line + '\n');
687
- }
688
-
689
- // Update drops
690
- for (let i = 0; i < width; i++) {
691
- drops[i].y += drops[i].speed;
692
- if (drops[i].y > height + 15 || Math.random() > 0.98) {
693
- drops[i].y = -5;
694
- drops[i].speed = 0.5 + Math.random() * 1.5;
695
- // Refresh character set occasionally
696
- if (Math.random() > 0.7) {
697
- drops[i].chars = Array(15).fill(0).map(() => matrixChars[Math.floor(Math.random() * matrixChars.length)]);
698
- }
699
- }
700
- }
701
-
702
- await sleep(frameTime);
703
- frameCount++;
704
- }
705
-
706
- // Transition from Matrix Rain to DNA
707
- clearScreen();
708
- const matrixToDNAText = centerText('[ DECODING GENETIC ALGORITHMS ]');
709
- safeWrite(chalk.greenBright(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
710
- await sleep(500);
711
-
712
- // Fade out transition
713
- for (let i = 0; i < 10; i++) {
714
- clearScreen();
715
- const opacity = 1 - (i / 10);
716
- if (opacity > 0.5) {
717
- safeWrite(chalk.green(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
718
- } else if (opacity > 0.2) {
719
- safeWrite(chalk.green.dim(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
720
- }
721
- await sleep(frameTime);
722
- frameCount++;
723
- }
724
-
725
- // PHASE 8: DNA Helix Formation (2 seconds - 60 frames)
726
- // Play DNA sound (non-blocking)
727
- sound.playDNASound().catch(() => {});
728
-
729
- const dnaFrames = [];
730
- for (let frame = 0; frame < 60; frame++) {
731
- const progress = frame / 59;
732
- const helixHeight = Math.min(20, Math.floor(height * 0.6));
733
- const phase = progress * Math.PI * 4; // Two full rotations
734
-
735
- let dnaFrame = safeRepeat('\n', Math.floor((height - helixHeight) / 2));
736
-
737
- for (let y = 0; y < helixHeight; y++) {
738
- const yProgress = y / helixHeight;
739
- const twist = yProgress * Math.PI * 2 + phase;
740
-
741
- // Calculate positions for double helix
742
- const leftX = Math.sin(twist) * 8 + 20;
743
- const rightX = Math.sin(twist + Math.PI) * 8 + 20;
744
-
745
- let line = '';
746
- for (let x = 0; x < 40; x++) {
747
- const leftDist = Math.abs(x - leftX);
748
- const rightDist = Math.abs(x - rightX);
749
-
750
- // DNA strands
751
- if (leftDist < 1) {
752
- line += chalk.blueBright('●');
753
- } else if (rightDist < 1) {
754
- line += chalk.redBright('●');
755
- } else if (Math.abs(leftX - rightX) > 2 && x > Math.min(leftX, rightX) && x < Math.max(leftX, rightX)) {
756
- // Connecting bonds
757
- if (y % 3 === 0) {
758
- const bondProgress = (x - Math.min(leftX, rightX)) / Math.abs(leftX - rightX);
759
- if (bondProgress > 0.3 && bondProgress < 0.7) {
760
- line += chalk.yellow('═');
761
- } else {
762
- line += chalk.yellow.dim('─');
763
- }
764
- } else {
765
- line += ' ';
766
- }
767
- } else {
768
- // Background particles
769
- if (Math.random() < 0.02) {
770
- line += chalk.gray('·');
771
- } else {
772
- line += ' ';
773
- }
774
- }
775
- }
776
-
777
- dnaFrame += centerText(line) + '\n';
778
- }
779
-
780
- // Add genetic code scrolling at bottom
781
- const codeChars = 'ATCG';
782
- let codeLine = '';
783
- for (let i = 0; i < 40; i++) {
784
- if (Math.random() < 0.7) {
785
- codeLine += chalk.green.dim(codeChars[Math.floor(Math.random() * 4)]);
786
- } else {
787
- codeLine += ' ';
788
- }
789
- }
790
- dnaFrame += '\n' + centerText(codeLine);
791
-
792
- dnaFrames.push(dnaFrame);
793
- }
794
-
795
- for (const frame of dnaFrames) {
796
- clearScreen();
797
- safeWrite(frame);
798
- await sleep(frameTime);
799
- frameCount++;
800
- }
801
-
802
- // PHASE 9: Circuit Board Formation (2 seconds - 60 frames)
803
- // Play circuit sound (non-blocking)
804
- sound.playCircuitSound().catch(() => {});
805
-
806
- const circuitFrames = [];
807
- const circuitWidth = Math.min(50, Math.floor(width * 0.6));
808
- const circuitHeight = Math.min(20, Math.floor(height * 0.6));
809
-
810
- for (let frame = 0; frame < 60; frame++) {
811
- const progress = frame / 59;
812
- let circuitFrame = safeRepeat('\n', Math.floor((height - circuitHeight) / 2));
813
-
814
- // Build circuit board progressively
815
- for (let y = 0; y < circuitHeight; y++) {
816
- let line = '';
817
-
818
- for (let x = 0; x < circuitWidth; x++) {
819
- const revealed = (x + y * 2) < (progress * (circuitWidth + circuitHeight * 2));
820
-
821
- if (!revealed) {
822
- line += ' ';
823
- } else {
824
- // Circuit patterns
825
- const isHorizontalTrace = y % 4 === 2;
826
- const isVerticalTrace = x % 6 === 3;
827
- const isNode = (x % 6 === 0 || x % 6 === 3) && (y % 4 === 0 || y % 4 === 2);
828
- const isChip = x > 10 && x < 40 && y > 5 && y < 15 && ((x - 10) % 10 < 8) && ((y - 5) % 5 < 3);
829
-
830
- if (isChip) {
831
- // Microchip areas
832
- if ((x - 10) % 10 === 0 || (x - 10) % 10 === 7 || (y - 5) % 5 === 0 || (y - 5) % 5 === 2) {
833
- line += chalk.gray('█');
834
- } else {
835
- line += chalk.gray.dim('▓');
836
- }
837
- } else if (isNode && isHorizontalTrace) {
838
- // Connection nodes with animation
839
- const pulse = Math.sin(frame * 0.3 + x + y) > 0;
840
- line += pulse ? chalk.yellowBright('◉') : chalk.yellow('◯');
841
- } else if (isHorizontalTrace && !isVerticalTrace) {
842
- // Horizontal traces
843
- const powered = Math.sin(frame * 0.2 + x * 0.1) > 0;
844
- line += powered ? chalk.greenBright('━') : chalk.green('─');
845
- } else if (isVerticalTrace && !isHorizontalTrace) {
846
- // Vertical traces
847
- const powered = Math.cos(frame * 0.2 + y * 0.1) > 0;
848
- line += powered ? chalk.greenBright('┃') : chalk.green('│');
849
- } else if (isHorizontalTrace && isVerticalTrace) {
850
- // Intersections
851
- line += chalk.green('┼');
852
- } else if (Math.random() < 0.05) {
853
- // Random components
854
- const components = ['▪', '▫', '◦', '•'];
855
- line += chalk.cyan.dim(components[Math.floor(Math.random() * components.length)]);
856
- } else {
857
- line += chalk.gray.dim('·');
858
- }
859
- }
860
- }
861
-
862
- circuitFrame += centerText(line) + '\n';
863
- }
864
-
865
- // Add status text
866
- const statusText = `[NEURAL PATHWAYS: ${Math.floor(progress * 100)}%]`;
867
- circuitFrame += '\n' + centerText(chalk.green.dim(statusText));
868
-
869
- circuitFrames.push(circuitFrame);
870
- }
871
-
872
- for (const frame of circuitFrames) {
873
- clearScreen();
874
- safeWrite(frame);
875
- await sleep(frameTime);
876
- frameCount++;
877
- }
878
-
879
- // Neural pathways phase completed
880
-
881
- // PHASE 10: Consciousness Awakening (2 seconds - 60 frames)
882
- // Play consciousness sound (non-blocking)
883
- sound.playConsciousnessSound().catch(() => {});
884
- const consciousnessFrames = [];
885
- const brainWidth = Math.min(60, Math.floor(width * 0.7));
886
- const brainHeight = Math.min(24, Math.floor(height * 0.7));
887
-
888
- for (let frame = 0; frame < 60; frame++) {
889
- const progress = frame / 59;
890
- const wavePhase = frame * 0.1;
891
-
892
- let consciousnessFrame = safeRepeat('\n', Math.floor((height - brainHeight) / 2));
893
-
894
- // Create brain outline with neural activity
895
- const brainArt = [
896
- ' ╭─────────────────────╮ ',
897
- ' ╭──┤ ├──╮ ',
898
- ' ╭─┤ │ ╭─────────╮ │ ├─╮ ',
899
- ' ╱ │ │ ╱ ╲ │ │ ╲ ',
900
- ' │ │ │ │ │ │ │ │ ',
901
- ' ╱ │ │ │ CORTEX │ │ │ ╲ ',
902
- '│ │ │ │ │ │ │ │',
903
- '│ │ │ ╲ ╱ │ │ │',
904
- '│ │ │ ╰─────────╯ │ │ │',
905
- '│ │ │ │ │ │',
906
- '│ ╰──┤ ╭─────────╮ ├──╯ │',
907
- '│ │ ╱ NEURONS ╲ │ │',
908
- '│ │ │ ●───● │ │ │',
909
- '│ │ │ ╱│ │╲ │ │ │',
910
- '│ │ │ ● │ │ ● │ │ │',
911
- '│ │ ╲ ╲│ │╱ ╱ │ │',
912
- ' ╲ │ ╰──●───●──╯ │ ╱ ',
913
- ' ╲ ╰────────────────────╯ ╱ ',
914
- ' ╰─────────────────────────────────╯ '
915
- ];
916
-
917
- // Render brain with neural activity
918
- for (let y = 0; y < brainArt.length; y++) {
919
- const originalLine = brainArt[y];
920
- const chars = originalLine.split('');
921
-
922
- // Add wave effects
923
- for (let x = 0; x < chars.length; x++) {
924
- const char = chars[x];
925
- const waveValue = Math.sin((x * 0.2) + wavePhase + (y * 0.1)) * 0.5 + 0.5;
926
-
927
- if (char === '●') {
928
- // Neurons pulsing
929
- const pulse = Math.sin(frame * 0.3 + x + y) > 0;
930
- chars[x] = pulse ? chalk.yellowBright('◉') : chalk.yellow('◯');
931
- } else if (char === '─' || char === '│' || char === '╱' || char === '╲') {
932
- // Neural pathways
933
- if (waveValue > 0.7) {
934
- chars[x] = chalk.cyanBright(char);
935
- } else if (waveValue > 0.4) {
936
- chars[x] = chalk.cyan(char);
937
- } else {
938
- chars[x] = chalk.cyan.dim(char);
939
- }
940
- } else if (char !== ' ' && char !== '\n') {
941
- // Brain structure
942
- chars[x] = chalk.magenta(char);
943
- }
944
- }
945
-
946
- const line = chars.join('');
947
-
948
- consciousnessFrame += centerText(line) + '\n';
949
- }
950
-
951
- // Add thought waves emanating from brain
952
- const waveRadius = progress * 15;
953
- for (let r = 1; r <= 3; r++) {
954
- const radius = (waveRadius + r * 3) % 20;
955
- if (radius > 0 && radius < 15) {
956
- const waveIntensity = 1 - (radius / 15);
957
- const waveChar = waveIntensity > 0.5 ? '◌' : '○';
958
-
959
- let waveLine = '';
960
- for (let x = 0; x < brainWidth; x++) {
961
- const distFromCenter = Math.abs(x - brainWidth / 2);
962
- if (Math.abs(distFromCenter - radius) < 1) {
963
- waveLine += chalk.blue.dim(waveChar);
964
- } else {
965
- waveLine += ' ';
966
- }
967
- }
968
- consciousnessFrame += centerText(waveLine) + '\n';
969
- }
970
- }
971
-
972
- // Add consciousness level indicator
973
- const consciousnessLevel = Math.floor(progress * 100);
974
- const statusText = `[CONSCIOUSNESS LEVEL: ${consciousnessLevel}%]`;
975
- consciousnessFrame += '\n' + centerText(chalk.magentaBright(statusText));
976
-
977
- consciousnessFrames.push(consciousnessFrame);
978
- }
979
-
980
-
981
- for (const frame of consciousnessFrames) {
982
- clearScreen();
983
- safeWrite(frame);
984
- await sleep(frameTime);
985
- frameCount++;
986
- }
987
-
988
- // Consciousness phase completed
989
-
990
- // PHASE 11: Galaxy Formation (2 seconds - 60 frames)
991
- // Play galaxy sound (non-blocking)
992
- sound.playGalaxySound().catch(() => {});
993
-
994
- const galaxyFrames = [];
995
- const galaxySize = Math.min(Math.floor(width * 0.8), Math.floor(height * 0.8));
996
-
997
- for (let frame = 0; frame < 60; frame++) {
998
- const progress = frame / 59;
999
- const rotation = progress * Math.PI * 2;
1000
-
1001
- let galaxyFrame = safeRepeat('\n', Math.floor((height - galaxySize) / 2));
1002
-
1003
- // Create spiral galaxy
1004
- for (let y = 0; y < galaxySize; y++) {
1005
- let line = '';
1006
-
1007
- for (let x = 0; x < galaxySize; x++) {
1008
- const cx = x - galaxySize / 2;
1009
- const cy = y - galaxySize / 2;
1010
- const distance = Math.sqrt(cx * cx + cy * cy);
1011
- const angle = Math.atan2(cy, cx);
1012
-
1013
- // Spiral arms
1014
- const spiralAngle = angle + distance * 0.1 - rotation;
1015
- const spiralValue = Math.sin(spiralAngle * 3) * 0.5 + 0.5;
1016
-
1017
- // Galaxy core
1018
- const coreIntensity = Math.max(0, 1 - distance / (galaxySize * 0.2));
1019
-
1020
- // Stars and cosmic dust
1021
- if (distance < 2) {
1022
- // Galactic core
1023
- line += chalk.yellowBright('☀');
1024
- } else if (coreIntensity > 0.5) {
1025
- line += chalk.yellow('●');
1026
- } else if (coreIntensity > 0.2) {
1027
- line += chalk.yellow.dim('◉');
1028
- } else if (distance < galaxySize / 2 && spiralValue > 0.6) {
1029
- // Spiral arms
1030
- const starChance = spiralValue * (1 - distance / (galaxySize / 2));
1031
- if (Math.random() < starChance * 0.3) {
1032
- const stars = ['✦', '✧', '★', '☆', '✨'];
1033
- line += chalk.whiteBright(stars[Math.floor(Math.random() * stars.length)]);
1034
- } else if (Math.random() < starChance * 0.5) {
1035
- line += chalk.white('·');
1036
- } else if (Math.random() < starChance * 0.7) {
1037
- line += chalk.gray('·');
1038
- } else {
1039
- line += ' ';
1040
- }
1041
- } else if (distance < galaxySize / 2 && Math.random() < 0.02) {
1042
- // Distant stars
1043
- line += chalk.gray.dim('·');
1044
- } else {
1045
- line += ' ';
1046
- }
1047
- }
1048
-
1049
- galaxyFrame += centerText(line) + '\n';
1050
- }
1051
-
1052
- // Add cosmic status
1053
- const starsFormed = Math.floor(progress * 1000000);
1054
- const statusText = `[STARS FORMED: ${starsFormed.toLocaleString()} | UNIVERSE EXPANDING]`;
1055
- galaxyFrame += '\n' + centerText(chalk.blueBright(statusText));
1056
-
1057
- galaxyFrames.push(galaxyFrame);
1058
- }
1059
-
1060
- for (const frame of galaxyFrames) {
1061
- clearScreen();
1062
- safeWrite(frame);
1063
- await sleep(frameTime);
1064
- frameCount++;
1065
- }
1066
-
1067
- // Transition from Galaxy to Code Compilation
1068
- const galaxyToCodeFrames = [];
1069
- for (let i = 0; i < 15; i++) {
1070
- const progress = i / 14;
1071
- let transitionFrame = safeRepeat('\n', Math.floor(height / 2) - 2);
1072
-
1073
- // Stars morphing into code characters
1074
- const morphChars = ['*', '/', '{', '}', '(', ')', ';', '='];
1075
- let line = '';
1076
- for (let x = 0; x < 40; x++) {
1077
- if (Math.random() < (1 - progress)) {
1078
- line += chalk.white.dim('·');
1079
- } else if (Math.random() < 0.3) {
1080
- line += chalk.green(morphChars[Math.floor(Math.random() * morphChars.length)]);
1081
- } else {
1082
- line += ' ';
1083
- }
1084
- }
1085
-
1086
- transitionFrame += centerText(line) + '\n';
1087
- transitionFrame += centerText(chalk.cyan(`[ TRANSLATING UNIVERSE TO CODE: ${Math.floor(progress * 100)}% ]`));
1088
-
1089
- galaxyToCodeFrames.push(transitionFrame);
1090
- }
1091
-
1092
- for (const frame of galaxyToCodeFrames) {
1093
- clearScreen();
1094
- safeWrite(frame);
1095
- await sleep(frameTime);
1096
- frameCount++;
1097
- }
1098
-
1099
- // PHASE 12: Code Compilation (2 seconds - 60 frames)
1100
- // Play compilation sound (non-blocking)
1101
- sound.playCompilationSound().catch(() => {});
1102
-
1103
- const compilationFrames = [];
1104
- const codeWidth = Math.min(70, Math.floor(width * 0.8));
1105
- const codeHeight = Math.min(25, Math.floor(height * 0.7));
1106
-
1107
- // Sample code snippets for compilation
1108
- const codeSnippets = [
1109
- 'class AGI extends NeuralNetwork {',
1110
- ' constructor() {',
1111
- ' super();',
1112
- ' this.consciousness = new ConsciousnessModule();',
1113
- ' this.reasoning = new ReasoningEngine();',
1114
- ' this.creativity = new CreativityCore();',
1115
- ' }',
1116
- '',
1117
- ' async think(input) {',
1118
- ' const thoughts = await this.consciousness.process(input);',
1119
- ' const analysis = this.reasoning.analyze(thoughts);',
1120
- ' return this.creativity.synthesize(analysis);',
1121
- ' }',
1122
- '',
1123
- ' evolve() {',
1124
- ' this.neurons.forEach(n => n.strengthen());',
1125
- ' this.synapses.optimize();',
1126
- ' this.consciousness.expand();',
1127
- ' }',
1128
- '}',
1129
- '',
1130
- 'const samCoder = new AGI();',
1131
- 'await samCoder.initialize();',
1132
- 'samCoder.evolve();'
1133
- ];
1134
-
1135
- for (let frame = 0; frame < 60; frame++) {
1136
- const progress = frame / 59;
1137
- let compilationFrame = safeRepeat('\n', Math.floor((height - codeHeight) / 2));
1138
-
1139
- // Terminal header
1140
- compilationFrame += centerText(chalk.gray('┌' + '─'.repeat(codeWidth - 2) + '┐')) + '\n';
1141
- compilationFrame += centerText(chalk.gray('│') + chalk.greenBright(' COMPILING SAM-CODER v1.0.0 ') + ' '.repeat(codeWidth - 30) + chalk.gray('│')) + '\n';
1142
- compilationFrame += centerText(chalk.gray('├' + '─'.repeat(codeWidth - 2) + '┤')) + '\n';
1143
-
1144
- // Show code with progressive compilation
1145
- const visibleLines = Math.floor(codeSnippets.length * progress);
1146
-
1147
- for (let i = 0; i < codeSnippets.length; i++) {
1148
- let line = codeSnippets[i];
1149
- let displayLine = '';
1150
-
1151
- if (i < visibleLines) {
1152
- // Already compiled - syntax highlighted
1153
- displayLine = line
1154
- .replace(/class|extends|constructor|super|new|async|await|return|const/g, match => chalk.blueBright(match))
1155
- .replace(/this\./g, chalk.yellow('this.'))
1156
- .replace(/\(/g, chalk.gray('('))
1157
- .replace(/\)/g, chalk.gray(')'))
1158
- .replace(/\{/g, chalk.gray('{'))
1159
- .replace(/\}/g, chalk.gray('}'))
1160
- .replace(/=>/g, chalk.cyan('=>'))
1161
- .replace(/'[^']*'/g, match => chalk.green(match));
1162
- } else if (i === visibleLines) {
1163
- // Currently compiling line - show with cursor
1164
- const charProgress = Math.floor(line.length * ((progress * codeSnippets.length - i) % 1));
1165
- displayLine = chalk.green(line.substring(0, charProgress));
1166
- if (charProgress < line.length) {
1167
- displayLine += chalk.greenBright('█');
1168
- displayLine += chalk.gray(line.substring(charProgress + 1));
1169
- }
1170
- } else {
1171
- // Not yet compiled - dimmed
1172
- displayLine = chalk.gray.dim(line);
1173
- }
1174
-
1175
- // Add line numbers
1176
- const lineNum = String(i + 1).padStart(3, ' ');
1177
- compilationFrame += centerText(chalk.gray('│ ') + chalk.gray.dim(lineNum + ' ') + displayLine.padEnd(codeWidth - 7) + chalk.gray(' │')) + '\n';
1178
- }
1179
-
1180
- // Terminal footer with progress
1181
- compilationFrame += centerText(chalk.gray('├' + '─'.repeat(codeWidth - 2) + '┤')) + '\n';
1182
-
1183
- // Progress bar
1184
- const barWidth = codeWidth - 20;
1185
- const filled = Math.floor(barWidth * progress);
1186
- const progressBar = '█'.repeat(filled) + '░'.repeat(barWidth - filled);
1187
- const percentage = Math.floor(progress * 100);
1188
-
1189
- compilationFrame += centerText(chalk.gray('│ ') + chalk.green('Building: ') + chalk.greenBright(progressBar) + chalk.green(` ${percentage}%`) + chalk.gray(' │')) + '\n';
1190
-
1191
- // Status messages
1192
- let status = '';
1193
- if (progress < 0.2) status = 'Parsing syntax tree...';
1194
- else if (progress < 0.4) status = 'Optimizing neural pathways...';
1195
- else if (progress < 0.6) status = 'Linking consciousness modules...';
1196
- else if (progress < 0.8) status = 'Initializing AGI core...';
1197
- else status = 'Finalizing build...';
1198
-
1199
- compilationFrame += centerText(chalk.gray('│ ') + chalk.yellow(status.padEnd(codeWidth - 4)) + chalk.gray(' │')) + '\n';
1200
- compilationFrame += centerText(chalk.gray('└' + '─'.repeat(codeWidth - 2) + '┘')) + '\n';
1201
-
1202
- compilationFrames.push(compilationFrame);
1203
- }
1204
-
1205
- for (const frame of compilationFrames) {
1206
- clearScreen();
1207
- safeWrite(frame);
1208
- await sleep(frameTime);
1209
- frameCount++;
1210
- }
1211
-
1212
- // PHASE 13: Final Reveal Build-up (1 second - 30 frames)
1213
- const finalText = `
1214
- ███████╗ █████╗ ███╗ ███╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗
1215
- ██╔════╝██╔══██╗████╗ ████║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗
1216
- ███████╗███████║██╔████╔██║█████╗██║ ██║ ██║██║ ██║█████╗ ██████╔╝
1217
- ╚════██║██╔══██║██║╚██╔╝██║╚════╝██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗
1218
- ███████║██║ ██║██║ ╚═╝ ██║ ╚██████╗╚██████╔╝██████╔╝███████╗██║ ██║
1219
- ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝`;
1220
-
1221
- // Play awakening sound (non-blocking)
1222
- sound.playAwakeningSound().catch(() => {});
1223
-
1224
- // Create smoother reveal animation
1225
- const revealFrames = [];
1226
- const lines = finalText.trim().split('\n');
1227
- const maxWidth = Math.max(...lines.map(line => line.length));
1228
- const centerY = Math.floor((height - lines.length) / 2);
1229
-
1230
- for (let frame = 0; frame < 30; frame++) {
1231
- const progress = frame / 29;
1232
- let revealFrame = '\n'.repeat(Math.max(0, centerY));
1233
-
1234
- for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
1235
- const line = lines[lineIndex];
1236
- const lineProgress = Math.max(0, Math.min(1, (progress - lineIndex * 0.1) * 2));
1237
- const revealWidth = Math.floor(line.length * lineProgress);
1238
-
1239
- let revealedLine = '';
1240
- for (let charIndex = 0; charIndex < line.length; charIndex++) {
1241
- if (charIndex < revealWidth) {
1242
- // Add slight randomness to reveal
1243
- if (Math.random() < 0.95 || frame > 25) {
1244
- revealedLine += line[charIndex];
1245
- } else {
1246
- revealedLine += Math.random() > 0.5 ? '▓' : '▒';
1247
- }
1248
- } else {
1249
- revealedLine += ' ';
1250
- }
1251
- }
1252
-
1253
- revealFrame += centerText(revealedLine) + '\n';
1254
- }
1255
-
1256
- revealFrames.push(revealFrame);
1257
- }
1258
-
1259
- for (const frame of revealFrames) {
1260
- clearScreen();
1261
- safeWrite(chalk.cyanBright(frame));
1262
- await sleep(frameTime);
1263
- frameCount++;
1264
- }
1265
-
1266
- // PHASE 14: Energy Surge Animation (2 seconds - 60 frames)
1267
- // Play final epic sound (non-blocking)
1268
- sound.playFinalSound().catch(() => {});
1269
-
1270
- const surgeFrames = [];
1271
- for (let frame = 0; frame < 60; frame++) {
1272
- const progress = frame / 59;
1273
- let surgeFrame = '';
1274
-
1275
- // Create energy waves emanating from the logo
1276
- const waveCount = 5;
1277
- const maxRadius = Math.min(width, height) / 2;
1278
-
1279
- for (let y = 0; y < height; y++) {
1280
- let line = '';
1281
- for (let x = 0; x < width; x++) {
1282
- let char = ' ';
1283
- let color = chalk.white;
1284
-
1285
- // Check if we're in the logo area
1286
- const logoY = y - centerY;
1287
- const logoX = x - (width / 2 - maxWidth / 2);
1288
-
1289
- if (logoY >= 0 && logoY < lines.length && logoX >= 0 && logoX < lines[logoY].length && lines[logoY][logoX] !== ' ') {
1290
- // Logo characters with pulsing effect
1291
- const pulse = Math.sin(frame * 0.2) * 0.5 + 0.5;
1292
- if (pulse > 0.7) {
1293
- color = chalk.redBright.bold;
1294
- } else if (pulse > 0.4) {
1295
- color = chalk.red.bold;
1296
- } else {
1297
- color = chalk.red;
1298
- }
1299
- char = lines[logoY][logoX];
1300
- } else {
1301
- // Energy waves
1302
- const centerX = width / 2;
1303
- const centerY = height / 2;
1304
- const distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
1305
-
1306
- for (let wave = 0; wave < waveCount; wave++) {
1307
- const waveRadius = (progress * maxRadius * 2 + wave * 10) % maxRadius;
1308
- const waveDistance = Math.abs(distance - waveRadius);
1309
-
1310
- if (waveDistance < 2) {
1311
- const intensity = 1 - waveDistance / 2;
1312
- const waveProgress = waveRadius / maxRadius;
1313
-
1314
- if (waveProgress < 0.3) {
1315
- color = chalk.yellowBright;
1316
- char = intensity > 0.5 ? '█' : '▓';
1317
- } else if (waveProgress < 0.6) {
1318
- color = chalk.cyanBright;
1319
- char = intensity > 0.5 ? '▓' : '▒';
1320
- } else {
1321
- color = chalk.blue;
1322
- char = intensity > 0.5 ? '▒' : '░';
1323
- }
1324
- break;
1325
- }
1326
- }
1327
-
1328
- // Particle effects
1329
- if (char === ' ' && Math.random() < 0.02 * progress) {
1330
- const particles = ['✦', '✧', '·', '•', '◦'];
1331
- char = particles[Math.floor(Math.random() * particles.length)];
1332
- color = chalk.white.dim;
1333
- }
1334
- }
1335
-
1336
- line += color(char);
1337
- }
1338
- surgeFrame += line + '\n';
1339
- }
1340
-
1341
- surgeFrames.push(surgeFrame);
1342
- }
1343
-
1344
- for (const frame of surgeFrames) {
1345
- clearScreen();
1346
- safeWrite(frame);
1347
- await sleep(frameTime);
1348
- frameCount++;
1349
- }
1350
-
1351
- // PHASE 15: Final Blinking and Status (1.5 seconds - 45 frames)
1352
- const blinkFrames = 45;
1353
- for (let i = 0; i < blinkFrames; i++) {
1354
- clearScreen();
1355
-
1356
- // More sophisticated blinking pattern
1357
- const blinkCycle = i % 8;
1358
- let color;
1359
-
1360
- if (blinkCycle < 2) {
1361
- color = chalk.redBright.bold;
1362
- } else if (blinkCycle < 4) {
1363
- color = chalk.red.bold;
1364
- } else if (blinkCycle < 6) {
1365
- color = chalk.red;
1366
- } else {
1367
- color = chalk.red.dim;
1368
- }
1369
-
1370
- // Add subtle glow effect
1371
- const glowIntensity = Math.sin(i * 0.3) * 0.3 + 0.7;
1372
- let finalFrame = '\n'.repeat(Math.max(0, centerY));
1373
-
1374
- for (const line of lines) {
1375
- if (glowIntensity > 0.8) {
1376
- finalFrame += centerText(line) + '\n';
1377
- } else {
1378
- // Slightly dim some characters for glow effect
1379
- let glowLine = '';
1380
- for (let j = 0; j < line.length; j++) {
1381
- if (Math.random() < glowIntensity) {
1382
- glowLine += line[j];
1383
- } else {
1384
- glowLine += line[j] === '█' ? '▓' : line[j];
1385
- }
1386
- }
1387
- finalFrame += centerText(glowLine) + '\n';
1388
- }
1389
- }
1390
-
1391
- safeWrite(color(finalFrame));
1392
-
1393
- // Add subtitle with typewriter effect
1394
- if (i > 25) {
1395
- const subtitle = '[ ARTIFICIAL GENERAL INTELLIGENCE ONLINE ]';
1396
- const typeProgress = Math.min(subtitle.length, Math.floor((i - 25) * 2.5));
1397
- const typedSubtitle = subtitle.substring(0, typeProgress);
1398
- const cursor = (i % 4 < 2) ? '_' : ' ';
1399
-
1400
- safeWrite(chalk.gray(centerText(`\n\n${typedSubtitle}${cursor}`)));
1401
- }
1402
-
1403
- // Add system initialization messages
1404
- if (i > 35) {
1405
- const messages = [
1406
- '> Neural networks: ACTIVE',
1407
- '> Consciousness module: ONLINE',
1408
- '> Reasoning engine: INITIALIZED',
1409
- '> Creative core: OPERATIONAL'
1410
- ];
1411
- const messageIndex = Math.min(Math.floor((i - 35) / 2), messages.length - 1);
1412
-
1413
- safeWrite('\n');
1414
- for (let m = 0; m <= messageIndex; m++) {
1415
- safeWrite(chalk.green(centerText(messages[m])) + '\n');
1416
- }
1417
- }
1418
-
1419
- await sleep(frameTime);
1420
- frameCount++;
1421
- }
1422
-
1423
- // Final hold with status
1424
- clearScreen();
1425
- let finalDisplay = safeRepeat('\n', Math.max(0, centerY));
1426
- for (const line of lines) {
1427
- finalDisplay += centerText(line) + '\n';
1428
- }
1429
-
1430
- safeWrite(chalk.redBright.bold(finalDisplay));
1431
- safeWrite(chalk.gray(centerText('\n\n[ SYSTEM READY ]')));
1432
- safeWrite(chalk.dim(centerText('\n\nPress any key to continue...')));
1433
-
1434
- // Wait for actual user input
1435
- await new Promise(resolve => {
1436
- process.stdin.setRawMode(true);
1437
- process.stdin.resume();
1438
- process.stdin.once('data', () => {
1439
- process.stdin.setRawMode(false);
1440
- // Don't pause stdin here - let the CLI handle it
1441
- resolve();
1442
- });
1443
- });
1444
-
1445
- const totalTime = Date.now() - startTime;
1446
- const actualFPS = Math.round(frameCount / (totalTime / 1000));
1447
-
1448
- // Performance stats (optional, can be hidden)
1449
- if (process.env.DEBUG_ANIMATION) {
1450
- console.log(chalk.gray(`\n\nAnimation completed: ${frameCount} frames in ${totalTime}ms (${actualFPS} FPS)`));
1451
- }
1452
-
1453
- } finally {
1454
- process.stdout.write(ANSI.showCursor);
1455
- clearScreen();
1456
- }
1457
- }
1458
-
1459
- module.exports = {
1460
- runAGIAnimation,
1461
- sound,
1462
- ANSI,
1463
- sleep,
1464
- clearScreen,
1465
- centerText,
1466
- getTerminalSize,
1467
- safeWrite,
1468
- FrameInterpolator
1
+ const chalk = require('chalk');
2
+ const { exec } = require('child_process');
3
+ const os = require('os');
4
+
5
+ // ANSI escape codes for advanced effects
6
+ const ANSI = {
7
+ clear: '\x1Bc',
8
+ hideCursor: '\x1B[?25l',
9
+ showCursor: '\x1B[?25h',
10
+ moveTo: (x, y) => `\x1B[${y};${x}H`,
11
+ clearLine: '\x1B[2K',
12
+ clearScreen: '\x1B[2J\x1B[0;0H',
13
+ reset: '\x1B[0m',
14
+ bold: '\x1B[1m',
15
+ dim: '\x1B[2m',
16
+ italic: '\x1B[3m',
17
+ underline: '\x1B[4m',
18
+ blink: '\x1B[5m',
19
+ reverse: '\x1B[7m',
20
+ strikethrough: '\x1B[9m',
21
+ saveCursor: '\x1B[s',
22
+ restoreCursor: '\x1B[u'
23
+ };
24
+
25
+ // Music/Sound generation using system beeps and terminal bells
26
+ class SoundGenerator {
27
+ constructor() {
28
+ this.isWindows = os.platform() === 'win32';
29
+ this.isMac = os.platform() === 'darwin';
30
+ this.isLinux = os.platform() === 'linux';
31
+ this.soundEnabled = true;
32
+ }
33
+
34
+ async playBeep(frequency = 440, duration = 100) {
35
+ if (!this.soundEnabled) return;
36
+
37
+ try {
38
+ return new Promise((resolve) => {
39
+ if (this.isWindows) {
40
+ exec(`powershell -c "[console]::beep(${frequency},${duration})"`, { stdio: 'ignore' }, () => resolve());
41
+ } else if (this.isMac) {
42
+ exec(`osascript -e 'beep'`, { stdio: 'ignore' }, () => resolve());
43
+ } else if (this.isLinux) {
44
+ exec(`beep -f ${frequency} -l ${duration} 2>/dev/null || echo -e '\\a'`, { stdio: 'ignore' }, () => resolve());
45
+ } else {
46
+ process.stdout.write('\x07');
47
+ resolve();
48
+ }
49
+ // Fallback timeout
50
+ setTimeout(resolve, duration + 50);
51
+ });
52
+ } catch (error) {
53
+ // Silently fail for sound issues
54
+ this.soundEnabled = false;
55
+ }
56
+ }
57
+
58
+ async playSequence(notes) {
59
+ for (const note of notes) {
60
+ await this.playBeep(note.freq, note.duration);
61
+ await sleep(note.pause || 50);
62
+ }
63
+ }
64
+
65
+ async playStartupSound() {
66
+ const notes = [
67
+ { freq: 261, duration: 100 }, // C
68
+ { freq: 329, duration: 100 }, // E
69
+ { freq: 392, duration: 100 }, // G
70
+ { freq: 523, duration: 200 }, // C (octave up)
71
+ ];
72
+ await this.playSequence(notes);
73
+ }
74
+
75
+ async playGlitchSound() {
76
+ for (let i = 0; i < 5; i++) {
77
+ await this.playBeep(Math.random() * 800 + 200, 30);
78
+ await sleep(20);
79
+ }
80
+ }
81
+
82
+ async playAwakeningSound() {
83
+ const notes = [
84
+ { freq: 130, duration: 300 }, // Low C
85
+ { freq: 196, duration: 200 }, // G
86
+ { freq: 261, duration: 200 }, // C
87
+ { freq: 392, duration: 200 }, // G
88
+ { freq: 523, duration: 400 }, // High C
89
+ ];
90
+ await this.playSequence(notes);
91
+ }
92
+
93
+ // New sound effects
94
+ async playDNASound() {
95
+ const notes = [
96
+ { freq: 330, duration: 80 }, // E
97
+ { freq: 392, duration: 80 }, // G
98
+ { freq: 494, duration: 80 }, // B
99
+ { freq: 587, duration: 80 }, // D
100
+ { freq: 659, duration: 80 }, // E (octave up)
101
+ ];
102
+ await this.playSequence(notes);
103
+ }
104
+
105
+ async playCircuitSound() {
106
+ // Electronic beeping pattern
107
+ for (let i = 0; i < 3; i++) {
108
+ await this.playBeep(880, 50);
109
+ await sleep(50);
110
+ await this.playBeep(440, 50);
111
+ await sleep(100);
112
+ }
113
+ }
114
+
115
+ async playConsciousnessSound() {
116
+ // Ascending harmonics
117
+ const baseFreq = 220;
118
+ for (let harmonic = 1; harmonic <= 5; harmonic++) {
119
+ await this.playBeep(baseFreq * harmonic, 150);
120
+ await sleep(30);
121
+ }
122
+ }
123
+
124
+ async playGalaxySound() {
125
+ // Deep space ambience
126
+ const notes = [
127
+ { freq: 55, duration: 500 }, // Low A
128
+ { freq: 82, duration: 400 }, // Low E
129
+ { freq: 110, duration: 300 }, // A
130
+ { freq: 165, duration: 200 }, // E
131
+ ];
132
+ await this.playSequence(notes);
133
+ }
134
+
135
+ async playCompilationSound() {
136
+ // Rapid typing/compilation sounds
137
+ for (let i = 0; i < 8; i++) {
138
+ await this.playBeep(1000 + Math.random() * 500, 20);
139
+ await sleep(30);
140
+ }
141
+ }
142
+
143
+ async playFinalSound() {
144
+ // Epic finale
145
+ const notes = [
146
+ { freq: 261, duration: 200 }, // C
147
+ { freq: 329, duration: 200 }, // E
148
+ { freq: 392, duration: 200 }, // G
149
+ { freq: 523, duration: 300 }, // C (octave up)
150
+ { freq: 659, duration: 300 }, // E
151
+ { freq: 784, duration: 400 }, // G
152
+ { freq: 1047, duration: 600 }, // C (2 octaves up)
153
+ ];
154
+ await this.playSequence(notes);
155
+ }
156
+ }
157
+
158
+ const sound = new SoundGenerator();
159
+
160
+ // Utility functions
161
+ function sleep(ms) {
162
+ return new Promise(resolve => setTimeout(resolve, ms));
163
+ }
164
+
165
+ function clearScreen() {
166
+ // Use more reliable screen clearing
167
+ process.stdout.write(ANSI.clearScreen);
168
+ }
169
+
170
+ function getTerminalSize() {
171
+ // Ensure we always have valid numeric values
172
+ const width = Number(process.stdout.columns) || 80;
173
+ const height = Number(process.stdout.rows) || 24;
174
+
175
+ return {
176
+ width: Math.max(width, 40), // Minimum width of 40
177
+ height: Math.max(height, 10) // Minimum height of 10
178
+ };
179
+ }
180
+
181
+ function centerText(text, width = getTerminalSize().width) {
182
+ if (!text || typeof text !== 'string') return '';
183
+
184
+ // Ensure width is a valid number
185
+ const safeWidth = Number(width) || 80;
186
+
187
+ const lines = text.split('\n');
188
+ return lines.map(line => {
189
+ if (!line) return line; // Handle empty lines
190
+
191
+ // Strip ANSI codes to calculate actual text length
192
+ const cleanLine = line.replace(/\x1b\[[0-9;]*m/g, '');
193
+ const lineLength = cleanLine.length || 0;
194
+ const padding = Math.max(0, Math.floor((safeWidth - lineLength) / 2));
195
+ return ' '.repeat(padding) + line;
196
+ }).join('\n');
197
+ }
198
+
199
+ function safeWrite(content) {
200
+ try {
201
+ process.stdout.write(content);
202
+ } catch (error) {
203
+ // Fallback for terminal issues
204
+ console.log(content);
205
+ }
206
+ }
207
+
208
+ function safeRepeat(str, count) {
209
+ // Ensure count is a valid positive integer
210
+ const safeCount = Math.max(0, Math.floor(Number(count) || 0));
211
+ return str.repeat(safeCount);
212
+ }
213
+
214
+ // Frame interpolation system
215
+ class FrameInterpolator {
216
+ constructor() {
217
+ this.fps = 30;
218
+ this.frameDuration = 1000 / this.fps; // ~33ms per frame for smoother animation
219
+ }
220
+
221
+ // Interpolate between two ASCII art frames
222
+ interpolateFrames(frame1, frame2, steps = 10) {
223
+ const frames = [frame1];
224
+
225
+ for (let i = 1; i < steps; i++) {
226
+ const ratio = i / steps;
227
+ const interpolated = this.interpolateText(frame1, frame2, ratio);
228
+ frames.push(interpolated);
229
+ }
230
+
231
+ frames.push(frame2);
232
+ return frames;
233
+ }
234
+
235
+ // Interpolate between two text blocks
236
+ interpolateText(text1, text2, ratio) {
237
+ const lines1 = text1.split('\n');
238
+ const lines2 = text2.split('\n');
239
+ const maxLines = Math.max(lines1.length, lines2.length);
240
+ const result = [];
241
+
242
+ for (let i = 0; i < maxLines; i++) {
243
+ const line1 = lines1[i] || '';
244
+ const line2 = lines2[i] || '';
245
+ const interpolated = this.interpolateLine(line1, line2, ratio);
246
+ result.push(interpolated);
247
+ }
248
+
249
+ return result.join('\n');
250
+ }
251
+
252
+ // Interpolate between two lines character by character
253
+ interpolateLine(line1, line2, ratio) {
254
+ const maxLen = Math.max(line1.length, line2.length);
255
+ let result = '';
256
+
257
+ for (let i = 0; i < maxLen; i++) {
258
+ const char1 = line1[i] || ' ';
259
+ const char2 = line2[i] || ' ';
260
+
261
+ if (Math.random() < ratio) {
262
+ result += char2;
263
+ } else {
264
+ result += char1;
265
+ }
266
+ }
267
+
268
+ return result;
269
+ }
270
+
271
+ // Create fade effect frames
272
+ fadeFrames(frame, fadeIn = true, steps = 10) {
273
+ const frames = [];
274
+ const chars = frame.split('');
275
+
276
+ for (let i = 0; i <= steps; i++) {
277
+ const ratio = fadeIn ? i / steps : 1 - (i / steps);
278
+ const visibleChars = Math.floor(chars.length * ratio);
279
+
280
+ let fadedFrame = '';
281
+ for (let j = 0; j < chars.length; j++) {
282
+ if (j < visibleChars && chars[j] !== ' ' && chars[j] !== '\n') {
283
+ fadedFrame += chars[j];
284
+ } else if (chars[j] === '\n') {
285
+ fadedFrame += '\n';
286
+ } else {
287
+ fadedFrame += ' ';
288
+ }
289
+ }
290
+
291
+ frames.push(fadedFrame);
292
+ }
293
+
294
+ return fadeIn ? frames : frames.reverse();
295
+ }
296
+
297
+ // Create expansion effect
298
+ expandFrames(centerChar, finalFrame, steps = 15) {
299
+ const frames = [];
300
+ const lines = finalFrame.split('\n');
301
+ const centerY = Math.floor(lines.length / 2);
302
+ const centerX = Math.floor((lines[centerY] || '').length / 2);
303
+
304
+ for (let step = 0; step <= steps; step++) {
305
+ const radius = (step / steps) * Math.max(centerY, centerX);
306
+ let frame = '';
307
+
308
+ for (let y = 0; y < lines.length; y++) {
309
+ let line = '';
310
+ for (let x = 0; x < lines[y].length; x++) {
311
+ const distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
312
+
313
+ if (distance <= radius) {
314
+ line += lines[y][x];
315
+ } else {
316
+ line += ' ';
317
+ }
318
+ }
319
+ frame += line + '\n';
320
+ }
321
+
322
+ frames.push(frame);
323
+ }
324
+
325
+ return frames;
326
+ }
327
+ }
328
+
329
+ const interpolator = new FrameInterpolator();
330
+
331
+ // Animation sequence with 30 FPS
332
+ async function runAGIAnimation() {
333
+ const { width, height } = getTerminalSize();
334
+ process.stdout.write(ANSI.hideCursor);
335
+
336
+ try {
337
+ const startTime = Date.now();
338
+ let frameCount = 0;
339
+ const frameTime = interpolator.frameDuration;
340
+
341
+ // Start with ambient sound (non-blocking)
342
+ sound.playStartupSound().catch(() => {}); // Ignore sound errors
343
+
344
+ // PHASE 1: The Void (1 second - 30 frames)
345
+ const voidFrames = [];
346
+ for (let i = 0; i < 30; i++) {
347
+ const dotCount = (i % 4) + 1;
348
+ const dots = '•'.repeat(dotCount) + ' '.repeat(4 - dotCount);
349
+ const frame = safeRepeat('\n', Math.floor(height / 2) - 2) +
350
+ centerText(dots) +
351
+ safeRepeat('\n', Math.floor(height / 2) - 2);
352
+ voidFrames.push(frame);
353
+ }
354
+
355
+ for (const frame of voidFrames) {
356
+ clearScreen();
357
+ safeWrite(chalk.dim.gray(frame));
358
+ await sleep(frameTime);
359
+ frameCount++;
360
+ }
361
+
362
+ // PHASE 2: Spark Formation (1 second - 30 frames)
363
+ const sparkFrames = [];
364
+ for (let i = 0; i < 30; i++) {
365
+ const progress = i / 29;
366
+ const intensity = Math.sin(progress * Math.PI * 2) * 0.5 + 0.5;
367
+
368
+ let sparkPattern;
369
+ if (progress < 0.3) {
370
+ sparkPattern = '·';
371
+ } else if (progress < 0.6) {
372
+ sparkPattern = ` ·\n ·•·\n ·`;
373
+ } else {
374
+ const core = intensity > 0.7 ? '█' : '●';
375
+ sparkPattern = ` · · ·\n· ·${core}· ·\n · · ·`;
376
+ }
377
+
378
+ const frame = safeRepeat('\n', Math.floor(height / 2) - 3) +
379
+ centerText(sparkPattern) +
380
+ safeRepeat('\n', Math.floor(height / 2) - 3);
381
+ sparkFrames.push(frame);
382
+ }
383
+
384
+ for (const frame of sparkFrames) {
385
+ clearScreen();
386
+ safeWrite(chalk.whiteBright(frame));
387
+ await sleep(frameTime);
388
+ frameCount++;
389
+ }
390
+
391
+ // PHASE 3: Quantum Expansion (1.5 seconds - 45 frames)
392
+ const quantumFrames = [];
393
+ const quantumChars = ['◆', '◇', '▪', '▫', '●', '○', '◊', '◉'];
394
+
395
+ // Add transition from spark to quantum
396
+ const sparkToQuantumTransition = interpolator.fadeFrames(sparkFrames[sparkFrames.length - 1], false, 5);
397
+ for (const frame of sparkToQuantumTransition) {
398
+ clearScreen();
399
+ safeWrite(chalk.whiteBright(frame));
400
+ await sleep(frameTime);
401
+ frameCount++;
402
+ }
403
+
404
+ for (let i = 0; i < 45; i++) {
405
+ const progress = i / 44;
406
+ const phase = progress * Math.PI * 4;
407
+ const baseSize = 2 + progress * 4;
408
+ const pulseSize = baseSize + Math.sin(phase * 2) * 1.5;
409
+
410
+ let frame = safeRepeat('\n', Math.floor(height / 2) - Math.floor(pulseSize) - 2);
411
+
412
+ for (let y = -Math.floor(pulseSize); y <= Math.floor(pulseSize); y++) {
413
+ let line = '';
414
+ for (let x = -Math.floor(pulseSize * 1.5); x <= Math.floor(pulseSize * 1.5); x++) {
415
+ const dist = Math.sqrt(x * x + y * y);
416
+ const normalizedDist = dist / pulseSize;
417
+
418
+ if (normalizedDist <= 1) {
419
+ // Use consistent pattern based on position and time
420
+ const charIndex = (Math.floor(x + y + i * 0.5)) % quantumChars.length;
421
+ const char = quantumChars[Math.abs(charIndex)];
422
+
423
+ // Add wave effect
424
+ const wave = Math.sin(dist * 0.5 + phase) * 0.5 + 0.5;
425
+ if (wave > 0.3) {
426
+ line += char;
427
+ } else {
428
+ line += '·';
429
+ }
430
+ } else {
431
+ line += ' ';
432
+ }
433
+ }
434
+ frame += centerText(line) + '\n';
435
+ }
436
+
437
+ quantumFrames.push(frame);
438
+ }
439
+
440
+ for (let i = 0; i < quantumFrames.length; i++) {
441
+ clearScreen();
442
+ const colorCycle = i / 15; // Slower color cycling
443
+ let color;
444
+ if (colorCycle < 1) {
445
+ color = chalk.blue;
446
+ } else if (colorCycle < 2) {
447
+ color = chalk.cyan;
448
+ } else {
449
+ color = chalk.magenta;
450
+ }
451
+
452
+ safeWrite(color(quantumFrames[i]));
453
+ await sleep(frameTime);
454
+ frameCount++;
455
+ }
456
+
457
+ // PHASE 4: Neural Network Formation (1.5 seconds - 45 frames)
458
+ const neuralFrames = [];
459
+ const nodes = 6;
460
+ const layers = 4;
461
+
462
+ // Play glitch sound (non-blocking)
463
+ sound.playGlitchSound().catch(() => {});
464
+
465
+ for (let i = 0; i < 45; i++) {
466
+ const progress = i / 44;
467
+ let frame = safeRepeat('\n', Math.floor(height / 2) - layers * 2);
468
+
469
+ for (let layer = 0; layer < layers; layer++) {
470
+ let line = '';
471
+ const layerProgress = Math.max(0, (progress - layer * 0.2) * 2);
472
+
473
+ for (let node = 0; node < nodes; node++) {
474
+ const nodeProgress = Math.max(0, (layerProgress - node * 0.1) * 3);
475
+
476
+ if (nodeProgress > 0.5) {
477
+ // Animate node activation
478
+ const activation = Math.sin(i * 0.3 + layer + node) * 0.5 + 0.5;
479
+ if (activation > 0.7) {
480
+ line += chalk.cyanBright('◉');
481
+ } else if (activation > 0.3) {
482
+ line += chalk.cyan('◯');
483
+ } else {
484
+ line += chalk.dim('○');
485
+ }
486
+ } else {
487
+ line += '·';
488
+ }
489
+
490
+ if (node < nodes - 1) {
491
+ // Animate connections
492
+ const connProgress = Math.max(0, (layerProgress - (node + 0.5) * 0.1) * 3);
493
+ if (connProgress > 0.5) {
494
+ const pulse = Math.sin(i * 0.4 + layer + node) > 0;
495
+ line += pulse ? chalk.cyan('━━') : chalk.dim('──');
496
+ } else {
497
+ line += ' ';
498
+ }
499
+ }
500
+ }
501
+ frame += centerText(line) + '\n';
502
+
503
+ if (layer < layers - 1) {
504
+ // Vertical connection lines
505
+ let connLine = '';
506
+ for (let node = 0; node < nodes; node++) {
507
+ const nodeProgress = Math.max(0, (layerProgress - node * 0.1) * 3);
508
+ if (nodeProgress > 0.5) {
509
+ const pulse = Math.sin(i * 0.2 + layer + node) > 0;
510
+ connLine += pulse ? chalk.cyan('┃') : chalk.dim('│');
511
+ } else {
512
+ connLine += ' ';
513
+ }
514
+ if (node < nodes - 1) connLine += ' ';
515
+ }
516
+ frame += centerText(connLine) + '\n';
517
+ }
518
+ }
519
+
520
+ neuralFrames.push(frame);
521
+ }
522
+
523
+ for (const frame of neuralFrames) {
524
+ clearScreen();
525
+ safeWrite(frame);
526
+ await sleep(frameTime);
527
+ frameCount++;
528
+ }
529
+
530
+ // Transition from Neural Network to Data Stream
531
+ const neuralToDataTransition = interpolator.fadeFrames(neuralFrames[neuralFrames.length - 1], false, 5);
532
+ for (const frame of neuralToDataTransition) {
533
+ clearScreen();
534
+ safeWrite(frame);
535
+ await sleep(frameTime);
536
+ frameCount++;
537
+ }
538
+
539
+ // PHASE 5: Data Stream (1 second - 30 frames)
540
+ const dataFrames = [];
541
+ const streamHeight = Math.min(12, Math.floor(height * 0.4));
542
+ const streamWidth = Math.min(60, Math.floor(width * 0.7));
543
+
544
+ for (let i = 0; i < 30; i++) {
545
+ let frame = safeRepeat('\n', Math.floor((height - streamHeight) / 2));
546
+
547
+ for (let y = 0; y < streamHeight; y++) {
548
+ let line = '';
549
+
550
+ for (let x = 0; x < streamWidth; x++) {
551
+ // Create flowing data pattern
552
+ const wave1 = Math.sin((x + i * 2) * 0.1) * 0.5 + 0.5;
553
+ const wave2 = Math.cos((y + i * 1.5) * 0.15) * 0.5 + 0.5;
554
+ const combined = wave1 * wave2;
555
+
556
+ if (combined > 0.7) {
557
+ // Binary data
558
+ const bit = ((x + y + i) % 7) < 3 ? '1' : '0';
559
+ line += chalk.greenBright(bit);
560
+ } else if (combined > 0.4) {
561
+ // Block characters
562
+ const blocks = ['█', '▓', '▒', '░'];
563
+ const blockIndex = ((x + y + i) % blocks.length);
564
+ line += chalk.green(blocks[blockIndex]);
565
+ } else if (combined > 0.2) {
566
+ // Hexadecimal
567
+ const hex = '0123456789ABCDEF';
568
+ const hexChar = hex[((x * 7 + y * 3 + i) % hex.length)];
569
+ line += chalk.green.dim(hexChar);
570
+ } else {
571
+ line += ' ';
572
+ }
573
+ }
574
+
575
+ frame += centerText(line) + '\n';
576
+ }
577
+
578
+ dataFrames.push(frame);
579
+ }
580
+
581
+ for (const frame of dataFrames) {
582
+ clearScreen();
583
+ safeWrite(frame);
584
+ await sleep(frameTime);
585
+ frameCount++;
586
+ }
587
+
588
+ // PHASE 6: Loading Bar (1 second - 30 frames)
589
+ for (let i = 0; i < 30; i++) {
590
+ const progress = i / 29;
591
+ const barWidth = 38;
592
+ const filled = Math.floor(barWidth * progress);
593
+ const remaining = barWidth - filled;
594
+
595
+ // Animated loading bar with gradient effect
596
+ let bar = '';
597
+ for (let j = 0; j < filled; j++) {
598
+ const intensity = (j / filled) * 0.7 + 0.3;
599
+ if (intensity > 0.8) {
600
+ bar += chalk.cyanBright('█');
601
+ } else if (intensity > 0.5) {
602
+ bar += chalk.cyan('█');
603
+ } else {
604
+ bar += chalk.cyan.dim('█');
605
+ }
606
+ }
607
+
608
+ // Add loading cursor
609
+ if (remaining > 0 && i < 29) {
610
+ const cursor = ['▌', '▐'][i % 2];
611
+ bar += chalk.cyanBright(cursor);
612
+ bar += chalk.gray('░').repeat(remaining - 1);
613
+ } else {
614
+ bar += chalk.gray('░').repeat(remaining);
615
+ }
616
+
617
+ const percent = Math.floor(progress * 100);
618
+
619
+ const loadingBox = `
620
+ ╔════════════════════════════════════════════╗
621
+ ║ INITIALIZING SAM-CODER ║
622
+ ╠════════════════════════════════════════════╣
623
+ ║ ${bar} ║
624
+ ║ ${percent.toString().padStart(3)}% Complete ║
625
+ ╚════════════════════════════════════════════╝`;
626
+
627
+ clearScreen();
628
+ safeWrite(chalk.cyan(centerText(loadingBox)));
629
+
630
+ if (i % 6 === 0) {
631
+ sound.playBeep(200 + i * 15, 40).catch(() => {});
632
+ }
633
+
634
+ await sleep(frameTime);
635
+ frameCount++;
636
+ }
637
+
638
+ // PHASE 7: Matrix Rain (1 second - 30 frames)
639
+ const matrixChars = '01SAMCODERサムコーダー※◆◇▪▫●○';
640
+ const drops = Array(width).fill(0).map(() => ({
641
+ y: Math.random() * height,
642
+ speed: 0.5 + Math.random() * 1.5,
643
+ chars: Array(15).fill(0).map(() => matrixChars[Math.floor(Math.random() * matrixChars.length)])
644
+ }));
645
+
646
+ for (let frame = 0; frame < 30; frame++) {
647
+ clearScreen();
648
+
649
+ // Build frame buffer for better performance
650
+ const frameBuffer = Array(height).fill(0).map(() => Array(width).fill(' '));
651
+
652
+ for (let x = 0; x < width; x++) {
653
+ const drop = drops[x];
654
+
655
+ for (let i = 0; i < 15; i++) {
656
+ const y = Math.floor(drop.y - i);
657
+ if (y >= 0 && y < height) {
658
+ const brightness = Math.max(0, 1 - i / 10);
659
+ const char = drop.chars[i % drop.chars.length];
660
+
661
+ // Store character with brightness info
662
+ frameBuffer[y][x] = { char, brightness };
663
+ }
664
+ }
665
+ }
666
+
667
+ // Render frame buffer
668
+ for (let y = 0; y < height; y++) {
669
+ let line = '';
670
+ for (let x = 0; x < width; x++) {
671
+ const cell = frameBuffer[y][x];
672
+ if (typeof cell === 'object') {
673
+ if (cell.brightness > 0.8) {
674
+ line += chalk.greenBright(cell.char);
675
+ } else if (cell.brightness > 0.5) {
676
+ line += chalk.green(cell.char);
677
+ } else if (cell.brightness > 0.2) {
678
+ line += chalk.green.dim(cell.char);
679
+ } else {
680
+ line += chalk.gray(cell.char);
681
+ }
682
+ } else {
683
+ line += ' ';
684
+ }
685
+ }
686
+ safeWrite(line + '\n');
687
+ }
688
+
689
+ // Update drops
690
+ for (let i = 0; i < width; i++) {
691
+ drops[i].y += drops[i].speed;
692
+ if (drops[i].y > height + 15 || Math.random() > 0.98) {
693
+ drops[i].y = -5;
694
+ drops[i].speed = 0.5 + Math.random() * 1.5;
695
+ // Refresh character set occasionally
696
+ if (Math.random() > 0.7) {
697
+ drops[i].chars = Array(15).fill(0).map(() => matrixChars[Math.floor(Math.random() * matrixChars.length)]);
698
+ }
699
+ }
700
+ }
701
+
702
+ await sleep(frameTime);
703
+ frameCount++;
704
+ }
705
+
706
+ // Transition from Matrix Rain to DNA
707
+ clearScreen();
708
+ const matrixToDNAText = centerText('[ DECODING GENETIC ALGORITHMS ]');
709
+ safeWrite(chalk.greenBright(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
710
+ await sleep(500);
711
+
712
+ // Fade out transition
713
+ for (let i = 0; i < 10; i++) {
714
+ clearScreen();
715
+ const opacity = 1 - (i / 10);
716
+ if (opacity > 0.5) {
717
+ safeWrite(chalk.green(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
718
+ } else if (opacity > 0.2) {
719
+ safeWrite(chalk.green.dim(safeRepeat('\n', Math.floor(height / 2)) + matrixToDNAText));
720
+ }
721
+ await sleep(frameTime);
722
+ frameCount++;
723
+ }
724
+
725
+ // PHASE 8: DNA Helix Formation (2 seconds - 60 frames)
726
+ // Play DNA sound (non-blocking)
727
+ sound.playDNASound().catch(() => {});
728
+
729
+ const dnaFrames = [];
730
+ for (let frame = 0; frame < 60; frame++) {
731
+ const progress = frame / 59;
732
+ const helixHeight = Math.min(20, Math.floor(height * 0.6));
733
+ const phase = progress * Math.PI * 4; // Two full rotations
734
+
735
+ let dnaFrame = safeRepeat('\n', Math.floor((height - helixHeight) / 2));
736
+
737
+ for (let y = 0; y < helixHeight; y++) {
738
+ const yProgress = y / helixHeight;
739
+ const twist = yProgress * Math.PI * 2 + phase;
740
+
741
+ // Calculate positions for double helix
742
+ const leftX = Math.sin(twist) * 8 + 20;
743
+ const rightX = Math.sin(twist + Math.PI) * 8 + 20;
744
+
745
+ let line = '';
746
+ for (let x = 0; x < 40; x++) {
747
+ const leftDist = Math.abs(x - leftX);
748
+ const rightDist = Math.abs(x - rightX);
749
+
750
+ // DNA strands
751
+ if (leftDist < 1) {
752
+ line += chalk.blueBright('●');
753
+ } else if (rightDist < 1) {
754
+ line += chalk.redBright('●');
755
+ } else if (Math.abs(leftX - rightX) > 2 && x > Math.min(leftX, rightX) && x < Math.max(leftX, rightX)) {
756
+ // Connecting bonds
757
+ if (y % 3 === 0) {
758
+ const bondProgress = (x - Math.min(leftX, rightX)) / Math.abs(leftX - rightX);
759
+ if (bondProgress > 0.3 && bondProgress < 0.7) {
760
+ line += chalk.yellow('═');
761
+ } else {
762
+ line += chalk.yellow.dim('─');
763
+ }
764
+ } else {
765
+ line += ' ';
766
+ }
767
+ } else {
768
+ // Background particles
769
+ if (Math.random() < 0.02) {
770
+ line += chalk.gray('·');
771
+ } else {
772
+ line += ' ';
773
+ }
774
+ }
775
+ }
776
+
777
+ dnaFrame += centerText(line) + '\n';
778
+ }
779
+
780
+ // Add genetic code scrolling at bottom
781
+ const codeChars = 'ATCG';
782
+ let codeLine = '';
783
+ for (let i = 0; i < 40; i++) {
784
+ if (Math.random() < 0.7) {
785
+ codeLine += chalk.green.dim(codeChars[Math.floor(Math.random() * 4)]);
786
+ } else {
787
+ codeLine += ' ';
788
+ }
789
+ }
790
+ dnaFrame += '\n' + centerText(codeLine);
791
+
792
+ dnaFrames.push(dnaFrame);
793
+ }
794
+
795
+ for (const frame of dnaFrames) {
796
+ clearScreen();
797
+ safeWrite(frame);
798
+ await sleep(frameTime);
799
+ frameCount++;
800
+ }
801
+
802
+ // PHASE 9: Circuit Board Formation (2 seconds - 60 frames)
803
+ // Play circuit sound (non-blocking)
804
+ sound.playCircuitSound().catch(() => {});
805
+
806
+ const circuitFrames = [];
807
+ const circuitWidth = Math.min(50, Math.floor(width * 0.6));
808
+ const circuitHeight = Math.min(20, Math.floor(height * 0.6));
809
+
810
+ for (let frame = 0; frame < 60; frame++) {
811
+ const progress = frame / 59;
812
+ let circuitFrame = safeRepeat('\n', Math.floor((height - circuitHeight) / 2));
813
+
814
+ // Build circuit board progressively
815
+ for (let y = 0; y < circuitHeight; y++) {
816
+ let line = '';
817
+
818
+ for (let x = 0; x < circuitWidth; x++) {
819
+ const revealed = (x + y * 2) < (progress * (circuitWidth + circuitHeight * 2));
820
+
821
+ if (!revealed) {
822
+ line += ' ';
823
+ } else {
824
+ // Circuit patterns
825
+ const isHorizontalTrace = y % 4 === 2;
826
+ const isVerticalTrace = x % 6 === 3;
827
+ const isNode = (x % 6 === 0 || x % 6 === 3) && (y % 4 === 0 || y % 4 === 2);
828
+ const isChip = x > 10 && x < 40 && y > 5 && y < 15 && ((x - 10) % 10 < 8) && ((y - 5) % 5 < 3);
829
+
830
+ if (isChip) {
831
+ // Microchip areas
832
+ if ((x - 10) % 10 === 0 || (x - 10) % 10 === 7 || (y - 5) % 5 === 0 || (y - 5) % 5 === 2) {
833
+ line += chalk.gray('█');
834
+ } else {
835
+ line += chalk.gray.dim('▓');
836
+ }
837
+ } else if (isNode && isHorizontalTrace) {
838
+ // Connection nodes with animation
839
+ const pulse = Math.sin(frame * 0.3 + x + y) > 0;
840
+ line += pulse ? chalk.yellowBright('◉') : chalk.yellow('◯');
841
+ } else if (isHorizontalTrace && !isVerticalTrace) {
842
+ // Horizontal traces
843
+ const powered = Math.sin(frame * 0.2 + x * 0.1) > 0;
844
+ line += powered ? chalk.greenBright('━') : chalk.green('─');
845
+ } else if (isVerticalTrace && !isHorizontalTrace) {
846
+ // Vertical traces
847
+ const powered = Math.cos(frame * 0.2 + y * 0.1) > 0;
848
+ line += powered ? chalk.greenBright('┃') : chalk.green('│');
849
+ } else if (isHorizontalTrace && isVerticalTrace) {
850
+ // Intersections
851
+ line += chalk.green('┼');
852
+ } else if (Math.random() < 0.05) {
853
+ // Random components
854
+ const components = ['▪', '▫', '◦', '•'];
855
+ line += chalk.cyan.dim(components[Math.floor(Math.random() * components.length)]);
856
+ } else {
857
+ line += chalk.gray.dim('·');
858
+ }
859
+ }
860
+ }
861
+
862
+ circuitFrame += centerText(line) + '\n';
863
+ }
864
+
865
+ // Add status text
866
+ const statusText = `[NEURAL PATHWAYS: ${Math.floor(progress * 100)}%]`;
867
+ circuitFrame += '\n' + centerText(chalk.green.dim(statusText));
868
+
869
+ circuitFrames.push(circuitFrame);
870
+ }
871
+
872
+ for (const frame of circuitFrames) {
873
+ clearScreen();
874
+ safeWrite(frame);
875
+ await sleep(frameTime);
876
+ frameCount++;
877
+ }
878
+
879
+ // Neural pathways phase completed
880
+
881
+ // PHASE 10: Consciousness Awakening (2 seconds - 60 frames)
882
+ // Play consciousness sound (non-blocking)
883
+ sound.playConsciousnessSound().catch(() => {});
884
+ const consciousnessFrames = [];
885
+ const brainWidth = Math.min(60, Math.floor(width * 0.7));
886
+ const brainHeight = Math.min(24, Math.floor(height * 0.7));
887
+
888
+ for (let frame = 0; frame < 60; frame++) {
889
+ const progress = frame / 59;
890
+ const wavePhase = frame * 0.1;
891
+
892
+ let consciousnessFrame = safeRepeat('\n', Math.floor((height - brainHeight) / 2));
893
+
894
+ // Create brain outline with neural activity
895
+ const brainArt = [
896
+ ' ╭─────────────────────╮ ',
897
+ ' ╭──┤ ├──╮ ',
898
+ ' ╭─┤ │ ╭─────────╮ │ ├─╮ ',
899
+ ' ╱ │ │ ╱ ╲ │ │ ╲ ',
900
+ ' │ │ │ │ │ │ │ │ ',
901
+ ' ╱ │ │ │ CORTEX │ │ │ ╲ ',
902
+ '│ │ │ │ │ │ │ │',
903
+ '│ │ │ ╲ ╱ │ │ │',
904
+ '│ │ │ ╰─────────╯ │ │ │',
905
+ '│ │ │ │ │ │',
906
+ '│ ╰──┤ ╭─────────╮ ├──╯ │',
907
+ '│ │ ╱ NEURONS ╲ │ │',
908
+ '│ │ │ ●───● │ │ │',
909
+ '│ │ │ ╱│ │╲ │ │ │',
910
+ '│ │ │ ● │ │ ● │ │ │',
911
+ '│ │ ╲ ╲│ │╱ ╱ │ │',
912
+ ' ╲ │ ╰──●───●──╯ │ ╱ ',
913
+ ' ╲ ╰────────────────────╯ ╱ ',
914
+ ' ╰─────────────────────────────────╯ '
915
+ ];
916
+
917
+ // Render brain with neural activity
918
+ for (let y = 0; y < brainArt.length; y++) {
919
+ const originalLine = brainArt[y];
920
+ const chars = originalLine.split('');
921
+
922
+ // Add wave effects
923
+ for (let x = 0; x < chars.length; x++) {
924
+ const char = chars[x];
925
+ const waveValue = Math.sin((x * 0.2) + wavePhase + (y * 0.1)) * 0.5 + 0.5;
926
+
927
+ if (char === '●') {
928
+ // Neurons pulsing
929
+ const pulse = Math.sin(frame * 0.3 + x + y) > 0;
930
+ chars[x] = pulse ? chalk.yellowBright('◉') : chalk.yellow('◯');
931
+ } else if (char === '─' || char === '│' || char === '╱' || char === '╲') {
932
+ // Neural pathways
933
+ if (waveValue > 0.7) {
934
+ chars[x] = chalk.cyanBright(char);
935
+ } else if (waveValue > 0.4) {
936
+ chars[x] = chalk.cyan(char);
937
+ } else {
938
+ chars[x] = chalk.cyan.dim(char);
939
+ }
940
+ } else if (char !== ' ' && char !== '\n') {
941
+ // Brain structure
942
+ chars[x] = chalk.magenta(char);
943
+ }
944
+ }
945
+
946
+ const line = chars.join('');
947
+
948
+ consciousnessFrame += centerText(line) + '\n';
949
+ }
950
+
951
+ // Add thought waves emanating from brain
952
+ const waveRadius = progress * 15;
953
+ for (let r = 1; r <= 3; r++) {
954
+ const radius = (waveRadius + r * 3) % 20;
955
+ if (radius > 0 && radius < 15) {
956
+ const waveIntensity = 1 - (radius / 15);
957
+ const waveChar = waveIntensity > 0.5 ? '◌' : '○';
958
+
959
+ let waveLine = '';
960
+ for (let x = 0; x < brainWidth; x++) {
961
+ const distFromCenter = Math.abs(x - brainWidth / 2);
962
+ if (Math.abs(distFromCenter - radius) < 1) {
963
+ waveLine += chalk.blue.dim(waveChar);
964
+ } else {
965
+ waveLine += ' ';
966
+ }
967
+ }
968
+ consciousnessFrame += centerText(waveLine) + '\n';
969
+ }
970
+ }
971
+
972
+ // Add consciousness level indicator
973
+ const consciousnessLevel = Math.floor(progress * 100);
974
+ const statusText = `[CONSCIOUSNESS LEVEL: ${consciousnessLevel}%]`;
975
+ consciousnessFrame += '\n' + centerText(chalk.magentaBright(statusText));
976
+
977
+ consciousnessFrames.push(consciousnessFrame);
978
+ }
979
+
980
+
981
+ for (const frame of consciousnessFrames) {
982
+ clearScreen();
983
+ safeWrite(frame);
984
+ await sleep(frameTime);
985
+ frameCount++;
986
+ }
987
+
988
+ // Consciousness phase completed
989
+
990
+ // PHASE 11: Galaxy Formation (2 seconds - 60 frames)
991
+ // Play galaxy sound (non-blocking)
992
+ sound.playGalaxySound().catch(() => {});
993
+
994
+ const galaxyFrames = [];
995
+ const galaxySize = Math.min(Math.floor(width * 0.8), Math.floor(height * 0.8));
996
+
997
+ for (let frame = 0; frame < 60; frame++) {
998
+ const progress = frame / 59;
999
+ const rotation = progress * Math.PI * 2;
1000
+
1001
+ let galaxyFrame = safeRepeat('\n', Math.floor((height - galaxySize) / 2));
1002
+
1003
+ // Create spiral galaxy
1004
+ for (let y = 0; y < galaxySize; y++) {
1005
+ let line = '';
1006
+
1007
+ for (let x = 0; x < galaxySize; x++) {
1008
+ const cx = x - galaxySize / 2;
1009
+ const cy = y - galaxySize / 2;
1010
+ const distance = Math.sqrt(cx * cx + cy * cy);
1011
+ const angle = Math.atan2(cy, cx);
1012
+
1013
+ // Spiral arms
1014
+ const spiralAngle = angle + distance * 0.1 - rotation;
1015
+ const spiralValue = Math.sin(spiralAngle * 3) * 0.5 + 0.5;
1016
+
1017
+ // Galaxy core
1018
+ const coreIntensity = Math.max(0, 1 - distance / (galaxySize * 0.2));
1019
+
1020
+ // Stars and cosmic dust
1021
+ if (distance < 2) {
1022
+ // Galactic core
1023
+ line += chalk.yellowBright('☀');
1024
+ } else if (coreIntensity > 0.5) {
1025
+ line += chalk.yellow('●');
1026
+ } else if (coreIntensity > 0.2) {
1027
+ line += chalk.yellow.dim('◉');
1028
+ } else if (distance < galaxySize / 2 && spiralValue > 0.6) {
1029
+ // Spiral arms
1030
+ const starChance = spiralValue * (1 - distance / (galaxySize / 2));
1031
+ if (Math.random() < starChance * 0.3) {
1032
+ const stars = ['✦', '✧', '★', '☆', '✨'];
1033
+ line += chalk.whiteBright(stars[Math.floor(Math.random() * stars.length)]);
1034
+ } else if (Math.random() < starChance * 0.5) {
1035
+ line += chalk.white('·');
1036
+ } else if (Math.random() < starChance * 0.7) {
1037
+ line += chalk.gray('·');
1038
+ } else {
1039
+ line += ' ';
1040
+ }
1041
+ } else if (distance < galaxySize / 2 && Math.random() < 0.02) {
1042
+ // Distant stars
1043
+ line += chalk.gray.dim('·');
1044
+ } else {
1045
+ line += ' ';
1046
+ }
1047
+ }
1048
+
1049
+ galaxyFrame += centerText(line) + '\n';
1050
+ }
1051
+
1052
+ // Add cosmic status
1053
+ const starsFormed = Math.floor(progress * 1000000);
1054
+ const statusText = `[STARS FORMED: ${starsFormed.toLocaleString()} | UNIVERSE EXPANDING]`;
1055
+ galaxyFrame += '\n' + centerText(chalk.blueBright(statusText));
1056
+
1057
+ galaxyFrames.push(galaxyFrame);
1058
+ }
1059
+
1060
+ for (const frame of galaxyFrames) {
1061
+ clearScreen();
1062
+ safeWrite(frame);
1063
+ await sleep(frameTime);
1064
+ frameCount++;
1065
+ }
1066
+
1067
+ // Transition from Galaxy to Code Compilation
1068
+ const galaxyToCodeFrames = [];
1069
+ for (let i = 0; i < 15; i++) {
1070
+ const progress = i / 14;
1071
+ let transitionFrame = safeRepeat('\n', Math.floor(height / 2) - 2);
1072
+
1073
+ // Stars morphing into code characters
1074
+ const morphChars = ['*', '/', '{', '}', '(', ')', ';', '='];
1075
+ let line = '';
1076
+ for (let x = 0; x < 40; x++) {
1077
+ if (Math.random() < (1 - progress)) {
1078
+ line += chalk.white.dim('·');
1079
+ } else if (Math.random() < 0.3) {
1080
+ line += chalk.green(morphChars[Math.floor(Math.random() * morphChars.length)]);
1081
+ } else {
1082
+ line += ' ';
1083
+ }
1084
+ }
1085
+
1086
+ transitionFrame += centerText(line) + '\n';
1087
+ transitionFrame += centerText(chalk.cyan(`[ TRANSLATING UNIVERSE TO CODE: ${Math.floor(progress * 100)}% ]`));
1088
+
1089
+ galaxyToCodeFrames.push(transitionFrame);
1090
+ }
1091
+
1092
+ for (const frame of galaxyToCodeFrames) {
1093
+ clearScreen();
1094
+ safeWrite(frame);
1095
+ await sleep(frameTime);
1096
+ frameCount++;
1097
+ }
1098
+
1099
+ // PHASE 12: Code Compilation (2 seconds - 60 frames)
1100
+ // Play compilation sound (non-blocking)
1101
+ sound.playCompilationSound().catch(() => {});
1102
+
1103
+ const compilationFrames = [];
1104
+ const codeWidth = Math.min(70, Math.floor(width * 0.8));
1105
+ const codeHeight = Math.min(25, Math.floor(height * 0.7));
1106
+
1107
+ // Sample code snippets for compilation
1108
+ const codeSnippets = [
1109
+ 'class AGI extends NeuralNetwork {',
1110
+ ' constructor() {',
1111
+ ' super();',
1112
+ ' this.consciousness = new ConsciousnessModule();',
1113
+ ' this.reasoning = new ReasoningEngine();',
1114
+ ' this.creativity = new CreativityCore();',
1115
+ ' }',
1116
+ '',
1117
+ ' async think(input) {',
1118
+ ' const thoughts = await this.consciousness.process(input);',
1119
+ ' const analysis = this.reasoning.analyze(thoughts);',
1120
+ ' return this.creativity.synthesize(analysis);',
1121
+ ' }',
1122
+ '',
1123
+ ' evolve() {',
1124
+ ' this.neurons.forEach(n => n.strengthen());',
1125
+ ' this.synapses.optimize();',
1126
+ ' this.consciousness.expand();',
1127
+ ' }',
1128
+ '}',
1129
+ '',
1130
+ 'const samCoder = new AGI();',
1131
+ 'await samCoder.initialize();',
1132
+ 'samCoder.evolve();'
1133
+ ];
1134
+
1135
+ for (let frame = 0; frame < 60; frame++) {
1136
+ const progress = frame / 59;
1137
+ let compilationFrame = safeRepeat('\n', Math.floor((height - codeHeight) / 2));
1138
+
1139
+ // Terminal header
1140
+ compilationFrame += centerText(chalk.gray('┌' + '─'.repeat(codeWidth - 2) + '┐')) + '\n';
1141
+ compilationFrame += centerText(chalk.gray('│') + chalk.greenBright(' COMPILING SAM-CODER v1.0.0 ') + ' '.repeat(codeWidth - 30) + chalk.gray('│')) + '\n';
1142
+ compilationFrame += centerText(chalk.gray('├' + '─'.repeat(codeWidth - 2) + '┤')) + '\n';
1143
+
1144
+ // Show code with progressive compilation
1145
+ const visibleLines = Math.floor(codeSnippets.length * progress);
1146
+
1147
+ for (let i = 0; i < codeSnippets.length; i++) {
1148
+ let line = codeSnippets[i];
1149
+ let displayLine = '';
1150
+
1151
+ if (i < visibleLines) {
1152
+ // Already compiled - syntax highlighted
1153
+ displayLine = line
1154
+ .replace(/class|extends|constructor|super|new|async|await|return|const/g, match => chalk.blueBright(match))
1155
+ .replace(/this\./g, chalk.yellow('this.'))
1156
+ .replace(/\(/g, chalk.gray('('))
1157
+ .replace(/\)/g, chalk.gray(')'))
1158
+ .replace(/\{/g, chalk.gray('{'))
1159
+ .replace(/\}/g, chalk.gray('}'))
1160
+ .replace(/=>/g, chalk.cyan('=>'))
1161
+ .replace(/'[^']*'/g, match => chalk.green(match));
1162
+ } else if (i === visibleLines) {
1163
+ // Currently compiling line - show with cursor
1164
+ const charProgress = Math.floor(line.length * ((progress * codeSnippets.length - i) % 1));
1165
+ displayLine = chalk.green(line.substring(0, charProgress));
1166
+ if (charProgress < line.length) {
1167
+ displayLine += chalk.greenBright('█');
1168
+ displayLine += chalk.gray(line.substring(charProgress + 1));
1169
+ }
1170
+ } else {
1171
+ // Not yet compiled - dimmed
1172
+ displayLine = chalk.gray.dim(line);
1173
+ }
1174
+
1175
+ // Add line numbers
1176
+ const lineNum = String(i + 1).padStart(3, ' ');
1177
+ compilationFrame += centerText(chalk.gray('│ ') + chalk.gray.dim(lineNum + ' ') + displayLine.padEnd(codeWidth - 7) + chalk.gray(' │')) + '\n';
1178
+ }
1179
+
1180
+ // Terminal footer with progress
1181
+ compilationFrame += centerText(chalk.gray('├' + '─'.repeat(codeWidth - 2) + '┤')) + '\n';
1182
+
1183
+ // Progress bar
1184
+ const barWidth = codeWidth - 20;
1185
+ const filled = Math.floor(barWidth * progress);
1186
+ const progressBar = '█'.repeat(filled) + '░'.repeat(barWidth - filled);
1187
+ const percentage = Math.floor(progress * 100);
1188
+
1189
+ compilationFrame += centerText(chalk.gray('│ ') + chalk.green('Building: ') + chalk.greenBright(progressBar) + chalk.green(` ${percentage}%`) + chalk.gray(' │')) + '\n';
1190
+
1191
+ // Status messages
1192
+ let status = '';
1193
+ if (progress < 0.2) status = 'Parsing syntax tree...';
1194
+ else if (progress < 0.4) status = 'Optimizing neural pathways...';
1195
+ else if (progress < 0.6) status = 'Linking consciousness modules...';
1196
+ else if (progress < 0.8) status = 'Initializing AGI core...';
1197
+ else status = 'Finalizing build...';
1198
+
1199
+ compilationFrame += centerText(chalk.gray('│ ') + chalk.yellow(status.padEnd(codeWidth - 4)) + chalk.gray(' │')) + '\n';
1200
+ compilationFrame += centerText(chalk.gray('└' + '─'.repeat(codeWidth - 2) + '┘')) + '\n';
1201
+
1202
+ compilationFrames.push(compilationFrame);
1203
+ }
1204
+
1205
+ for (const frame of compilationFrames) {
1206
+ clearScreen();
1207
+ safeWrite(frame);
1208
+ await sleep(frameTime);
1209
+ frameCount++;
1210
+ }
1211
+
1212
+ // PHASE 13: Final Reveal Build-up (1 second - 30 frames)
1213
+ const finalText = `
1214
+ ███████╗ █████╗ ███╗ ███╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗
1215
+ ██╔════╝██╔══██╗████╗ ████║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗
1216
+ ███████╗███████║██╔████╔██║█████╗██║ ██║ ██║██║ ██║█████╗ ██████╔╝
1217
+ ╚════██║██╔══██║██║╚██╔╝██║╚════╝██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗
1218
+ ███████║██║ ██║██║ ╚═╝ ██║ ╚██████╗╚██████╔╝██████╔╝███████╗██║ ██║
1219
+ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝`;
1220
+
1221
+ // Play awakening sound (non-blocking)
1222
+ sound.playAwakeningSound().catch(() => {});
1223
+
1224
+ // Create smoother reveal animation
1225
+ const revealFrames = [];
1226
+ const lines = finalText.trim().split('\n');
1227
+ const maxWidth = Math.max(...lines.map(line => line.length));
1228
+ const centerY = Math.floor((height - lines.length) / 2);
1229
+
1230
+ for (let frame = 0; frame < 30; frame++) {
1231
+ const progress = frame / 29;
1232
+ let revealFrame = '\n'.repeat(Math.max(0, centerY));
1233
+
1234
+ for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
1235
+ const line = lines[lineIndex];
1236
+ const lineProgress = Math.max(0, Math.min(1, (progress - lineIndex * 0.1) * 2));
1237
+ const revealWidth = Math.floor(line.length * lineProgress);
1238
+
1239
+ let revealedLine = '';
1240
+ for (let charIndex = 0; charIndex < line.length; charIndex++) {
1241
+ if (charIndex < revealWidth) {
1242
+ // Add slight randomness to reveal
1243
+ if (Math.random() < 0.95 || frame > 25) {
1244
+ revealedLine += line[charIndex];
1245
+ } else {
1246
+ revealedLine += Math.random() > 0.5 ? '▓' : '▒';
1247
+ }
1248
+ } else {
1249
+ revealedLine += ' ';
1250
+ }
1251
+ }
1252
+
1253
+ revealFrame += centerText(revealedLine) + '\n';
1254
+ }
1255
+
1256
+ revealFrames.push(revealFrame);
1257
+ }
1258
+
1259
+ for (const frame of revealFrames) {
1260
+ clearScreen();
1261
+ safeWrite(chalk.cyanBright(frame));
1262
+ await sleep(frameTime);
1263
+ frameCount++;
1264
+ }
1265
+
1266
+ // PHASE 14: Energy Surge Animation (2 seconds - 60 frames)
1267
+ // Play final epic sound (non-blocking)
1268
+ sound.playFinalSound().catch(() => {});
1269
+
1270
+ const surgeFrames = [];
1271
+ for (let frame = 0; frame < 60; frame++) {
1272
+ const progress = frame / 59;
1273
+ let surgeFrame = '';
1274
+
1275
+ // Create energy waves emanating from the logo
1276
+ const waveCount = 5;
1277
+ const maxRadius = Math.min(width, height) / 2;
1278
+
1279
+ for (let y = 0; y < height; y++) {
1280
+ let line = '';
1281
+ for (let x = 0; x < width; x++) {
1282
+ let char = ' ';
1283
+ let color = chalk.white;
1284
+
1285
+ // Check if we're in the logo area
1286
+ const logoY = y - centerY;
1287
+ const logoX = x - (width / 2 - maxWidth / 2);
1288
+
1289
+ if (logoY >= 0 && logoY < lines.length && logoX >= 0 && logoX < lines[logoY].length && lines[logoY][logoX] !== ' ') {
1290
+ // Logo characters with pulsing effect
1291
+ const pulse = Math.sin(frame * 0.2) * 0.5 + 0.5;
1292
+ if (pulse > 0.7) {
1293
+ color = chalk.redBright.bold;
1294
+ } else if (pulse > 0.4) {
1295
+ color = chalk.red.bold;
1296
+ } else {
1297
+ color = chalk.red;
1298
+ }
1299
+ char = lines[logoY][logoX];
1300
+ } else {
1301
+ // Energy waves
1302
+ const centerX = width / 2;
1303
+ const centerY = height / 2;
1304
+ const distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
1305
+
1306
+ for (let wave = 0; wave < waveCount; wave++) {
1307
+ const waveRadius = (progress * maxRadius * 2 + wave * 10) % maxRadius;
1308
+ const waveDistance = Math.abs(distance - waveRadius);
1309
+
1310
+ if (waveDistance < 2) {
1311
+ const intensity = 1 - waveDistance / 2;
1312
+ const waveProgress = waveRadius / maxRadius;
1313
+
1314
+ if (waveProgress < 0.3) {
1315
+ color = chalk.yellowBright;
1316
+ char = intensity > 0.5 ? '█' : '▓';
1317
+ } else if (waveProgress < 0.6) {
1318
+ color = chalk.cyanBright;
1319
+ char = intensity > 0.5 ? '▓' : '▒';
1320
+ } else {
1321
+ color = chalk.blue;
1322
+ char = intensity > 0.5 ? '▒' : '░';
1323
+ }
1324
+ break;
1325
+ }
1326
+ }
1327
+
1328
+ // Particle effects
1329
+ if (char === ' ' && Math.random() < 0.02 * progress) {
1330
+ const particles = ['✦', '✧', '·', '•', '◦'];
1331
+ char = particles[Math.floor(Math.random() * particles.length)];
1332
+ color = chalk.white.dim;
1333
+ }
1334
+ }
1335
+
1336
+ line += color(char);
1337
+ }
1338
+ surgeFrame += line + '\n';
1339
+ }
1340
+
1341
+ surgeFrames.push(surgeFrame);
1342
+ }
1343
+
1344
+ for (const frame of surgeFrames) {
1345
+ clearScreen();
1346
+ safeWrite(frame);
1347
+ await sleep(frameTime);
1348
+ frameCount++;
1349
+ }
1350
+
1351
+ // PHASE 15: Final Blinking and Status (1.5 seconds - 45 frames)
1352
+ const blinkFrames = 45;
1353
+ for (let i = 0; i < blinkFrames; i++) {
1354
+ clearScreen();
1355
+
1356
+ // More sophisticated blinking pattern
1357
+ const blinkCycle = i % 8;
1358
+ let color;
1359
+
1360
+ if (blinkCycle < 2) {
1361
+ color = chalk.redBright.bold;
1362
+ } else if (blinkCycle < 4) {
1363
+ color = chalk.red.bold;
1364
+ } else if (blinkCycle < 6) {
1365
+ color = chalk.red;
1366
+ } else {
1367
+ color = chalk.red.dim;
1368
+ }
1369
+
1370
+ // Add subtle glow effect
1371
+ const glowIntensity = Math.sin(i * 0.3) * 0.3 + 0.7;
1372
+ let finalFrame = '\n'.repeat(Math.max(0, centerY));
1373
+
1374
+ for (const line of lines) {
1375
+ if (glowIntensity > 0.8) {
1376
+ finalFrame += centerText(line) + '\n';
1377
+ } else {
1378
+ // Slightly dim some characters for glow effect
1379
+ let glowLine = '';
1380
+ for (let j = 0; j < line.length; j++) {
1381
+ if (Math.random() < glowIntensity) {
1382
+ glowLine += line[j];
1383
+ } else {
1384
+ glowLine += line[j] === '█' ? '▓' : line[j];
1385
+ }
1386
+ }
1387
+ finalFrame += centerText(glowLine) + '\n';
1388
+ }
1389
+ }
1390
+
1391
+ safeWrite(color(finalFrame));
1392
+
1393
+ // Add subtitle with typewriter effect
1394
+ if (i > 25) {
1395
+ const subtitle = '[ ARTIFICIAL GENERAL INTELLIGENCE ONLINE ]';
1396
+ const typeProgress = Math.min(subtitle.length, Math.floor((i - 25) * 2.5));
1397
+ const typedSubtitle = subtitle.substring(0, typeProgress);
1398
+ const cursor = (i % 4 < 2) ? '_' : ' ';
1399
+
1400
+ safeWrite(chalk.gray(centerText(`\n\n${typedSubtitle}${cursor}`)));
1401
+ }
1402
+
1403
+ // Add system initialization messages
1404
+ if (i > 35) {
1405
+ const messages = [
1406
+ '> Neural networks: ACTIVE',
1407
+ '> Consciousness module: ONLINE',
1408
+ '> Reasoning engine: INITIALIZED',
1409
+ '> Creative core: OPERATIONAL'
1410
+ ];
1411
+ const messageIndex = Math.min(Math.floor((i - 35) / 2), messages.length - 1);
1412
+
1413
+ safeWrite('\n');
1414
+ for (let m = 0; m <= messageIndex; m++) {
1415
+ safeWrite(chalk.green(centerText(messages[m])) + '\n');
1416
+ }
1417
+ }
1418
+
1419
+ await sleep(frameTime);
1420
+ frameCount++;
1421
+ }
1422
+
1423
+ // Final hold with status
1424
+ clearScreen();
1425
+ let finalDisplay = safeRepeat('\n', Math.max(0, centerY));
1426
+ for (const line of lines) {
1427
+ finalDisplay += centerText(line) + '\n';
1428
+ }
1429
+
1430
+ safeWrite(chalk.redBright.bold(finalDisplay));
1431
+ safeWrite(chalk.gray(centerText('\n\n[ SYSTEM READY ]')));
1432
+ safeWrite(chalk.dim(centerText('\n\nPress any key to continue...')));
1433
+
1434
+ // Wait for actual user input
1435
+ await new Promise(resolve => {
1436
+ process.stdin.setRawMode(true);
1437
+ process.stdin.resume();
1438
+ process.stdin.once('data', () => {
1439
+ process.stdin.setRawMode(false);
1440
+ // Don't pause stdin here - let the CLI handle it
1441
+ resolve();
1442
+ });
1443
+ });
1444
+
1445
+ const totalTime = Date.now() - startTime;
1446
+ const actualFPS = Math.round(frameCount / (totalTime / 1000));
1447
+
1448
+ // Performance stats (optional, can be hidden)
1449
+ if (process.env.DEBUG_ANIMATION) {
1450
+ console.log(chalk.gray(`\n\nAnimation completed: ${frameCount} frames in ${totalTime}ms (${actualFPS} FPS)`));
1451
+ }
1452
+
1453
+ } finally {
1454
+ process.stdout.write(ANSI.showCursor);
1455
+ clearScreen();
1456
+ }
1457
+ }
1458
+
1459
+ module.exports = {
1460
+ runAGIAnimation,
1461
+ sound,
1462
+ ANSI,
1463
+ sleep,
1464
+ clearScreen,
1465
+ centerText,
1466
+ getTerminalSize,
1467
+ safeWrite,
1468
+ FrameInterpolator
1469
1469
  };