UNPKG

terminal-chaos-generator

Version:

๐Ÿ”ฅ INSANE terminal effects! Glitch art, rainbow explosions, dancing ASCII, and mind-bending chaos for your command line!

362 lines (303 loc) โ€ข 13.4 kB
#!/usr/bin/env node const chalk = require('chalk'); const figlet = require('figlet'); const gradient = require('gradient-string'); const cursor = require('cli-cursor'); const keypress = require('keypress'); class TerminalChaosGenerator { constructor() { this.width = process.stdout.columns || 80; this.height = process.stdout.rows || 24; this.isRunning = false; this.currentMode = 'chaos'; this.frameCount = 0; // Make stdin begin emitting "keypress" events keypress(process.stdin); process.stdin.setRawMode(true); process.stdin.resume(); this.setupKeyHandlers(); } setupKeyHandlers() { process.stdin.on('keypress', (ch, key) => { if (key && key.ctrl && key.name === 'c') { this.stop(); } if (key && key.name === 'q') { this.stop(); } if (key && key.name === 'space') { this.isRunning = !this.isRunning; } if (ch === '1') this.currentMode = 'chaos'; if (ch === '2') this.currentMode = 'glitch'; if (ch === '3') this.currentMode = 'rainbow'; if (ch === '4') this.currentMode = 'dance'; if (ch === '5') this.currentMode = 'explosion'; if (ch === '6') this.currentMode = 'wave'; if (ch === '7') this.currentMode = 'spiral'; if (ch === '8') this.currentMode = 'drunk'; }); } clear() { process.stdout.write('\x1b[2J\x1b[H'); } hideCursor() { cursor.hide(); } showCursor() { cursor.show(); } randomChar() { const chars = '!@#$%^&*()_+-=[]{}|;:,.<>?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789โ™ โ™ฃโ™ฅโ™ฆโ˜…โ˜†โ™ชโ™ซโ˜ฏโ˜ฎโ˜ฃโ˜ขโ˜ญโœฆโœงโœฉโœชโœซโœฌโœญโœฎโœฏโœฐโœฑโœฒโœณโœดโœตโœถโœทโœธโœนโœบโœปโœผโœฝโœพโœฟโ€โโ‚โƒโ„โ…โ†โ‡โˆโ‰โŠโ‹โ—โ—‹โ—โ—‘โ—’โ—“โ—”โ—•โ—–โ——โ—˜โ—™โ—šโ—›โ—œโ—โ—žโ—Ÿโ— โ—กโ—ขโ—ฃโ—คโ—ฅโ—ฆโ—งโ—จโ—ฉโ—ชโ—ซโ—ฌโ—ญโ—ฎโ—ฏ'; return chars[Math.floor(Math.random() * chars.length)]; } randomColor() { const colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']; return colors[Math.floor(Math.random() * colors.length)]; } chaosMode() { this.clear(); let output = ''; // Create random chaos across the screen for (let row = 0; row < this.height - 2; row++) { for (let col = 0; col < this.width; col++) { const intensity = Math.sin(this.frameCount * 0.1 + row * 0.1 + col * 0.1) * 0.5 + 0.5; if (Math.random() < intensity * 0.3) { const char = this.randomChar(); const color = this.randomColor(); output += chalk[color](char); } else { output += ' '; } } output += '\n'; } // Add crazy status line const statusGradients = [ gradient.rainbow, gradient.pastel, gradient.retro, gradient.teen, gradient.mind ]; const status = `๐Ÿ”ฅ CHAOS MODE ${this.frameCount} ๐Ÿ”ฅ Press 1-8 for modes, Q to quit, SPACE to pause`; output += statusGradients[this.frameCount % statusGradients.length](status); process.stdout.write(output); } glitchMode() { this.clear(); let output = ''; // Create glitch effect with random displacement for (let row = 0; row < this.height - 2; row++) { const glitchIntensity = Math.random() > 0.9 ? Math.random() * 10 : 0; const displacement = Math.floor(glitchIntensity); let line = ''; for (let col = 0; col < this.width; col++) { if (Math.random() < 0.1) { const glitchChar = Math.random() > 0.5 ? 'โ–ˆ' : 'โ–“'; const colors = ['red', 'green', 'blue', 'magenta']; line += chalk[colors[Math.floor(Math.random() * colors.length)]](glitchChar); } else if (Math.random() < 0.05) { line += chalk.inverse(this.randomChar()); } else { line += ' '; } } // Add displacement for glitch effect if (displacement > 0) { line = line.substring(displacement) + line.substring(0, displacement); } output += line + '\n'; } output += gradient.retro(`โšก GLITCH MODE โšก Reality.exe has stopped working...`); process.stdout.write(output); } rainbowMode() { this.clear(); let output = ''; // Create rainbow waves for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col++) { const wave = Math.sin((col + this.frameCount) * 0.2) * 0.5 + 0.5; const wave2 = Math.cos((row + this.frameCount * 0.5) * 0.3) * 0.5 + 0.5; if (wave * wave2 > 0.3) { const hue = (col + row + this.frameCount) % 360; const char = ['โ—', 'โ—†', 'โ˜…', 'โ™ ', 'โ™ฃ', 'โ™ฅ', 'โ™ฆ'][Math.floor(wave * 7)]; line += chalk.hsl(hue, 100, 50)(char); } else { line += ' '; } } output += line + '\n'; } output += gradient.rainbow(`๐ŸŒˆ RAINBOW MODE ๐ŸŒˆ Taste the rainbow of madness!`); process.stdout.write(output); } danceMode() { this.clear(); // Dancing ASCII characters const dancers = ['(>^.^)>', '<(^.^<)', '^(^.^)^', 'v(^.^)v']; const dancer = dancers[Math.floor(this.frameCount / 5) % dancers.length]; // Create dancing pattern let output = ''; for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col += 10) { const phase = (this.frameCount + col + row) * 0.1; const amplitude = Math.sin(phase) * 3; const pos = col + Math.floor(amplitude); if (pos >= 0 && pos < this.width - dancer.length) { line += ' '.repeat(Math.max(0, pos - line.length)); line += chalk.hsl((this.frameCount * 5 + col) % 360, 100, 50)(dancer); } } output += line + '\n'; } output += gradient.teen(`๐Ÿ’ƒ DANCE MODE ๐Ÿ’ƒ Let the terminal boogie!`); process.stdout.write(output); } explosionMode() { this.clear(); let output = ''; const centerX = Math.floor(this.width / 2); const centerY = Math.floor(this.height / 2); const maxRadius = Math.min(centerX, centerY); const explosionRadius = (this.frameCount * 2) % (maxRadius + 10); for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col++) { const distance = Math.sqrt((col - centerX) ** 2 + (row - centerY) ** 2); if (Math.abs(distance - explosionRadius) < 3) { const intensity = 1 - Math.abs(distance - explosionRadius) / 3; const chars = ['*', 'โœฆ', 'โœง', 'โœฉ', 'โ—', 'โ—‰']; const char = chars[Math.floor(intensity * chars.length)]; const color = distance < explosionRadius / 2 ? 'white' : distance < explosionRadius * 0.8 ? 'yellow' : 'red'; line += chalk[color](char); } else if (distance < explosionRadius && Math.random() < 0.1) { line += chalk.gray('ยท'); } else { line += ' '; } } output += line + '\n'; } output += gradient.mind(`๐Ÿ’ฅ EXPLOSION MODE ๐Ÿ’ฅ BOOM! Mind = Blown!`); process.stdout.write(output); } waveMode() { this.clear(); let output = ''; for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col++) { const wave1 = Math.sin((col + this.frameCount * 2) * 0.1) * 5; const wave2 = Math.cos((row + this.frameCount) * 0.2) * 3; const combined = wave1 + wave2; if (Math.abs(combined - row + this.height/2) < 2) { const char = '~'; const hue = (col + this.frameCount) % 360; line += chalk.hsl(hue, 100, 50)(char); } else { line += ' '; } } output += line + '\n'; } output += gradient.summer(`๐ŸŒŠ WAVE MODE ๐ŸŒŠ Surfing the digital waves!`); process.stdout.write(output); } spiralMode() { this.clear(); let output = ''; const centerX = this.width / 2; const centerY = this.height / 2; for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col++) { const dx = col - centerX; const dy = row - centerY; const angle = Math.atan2(dy, dx); const distance = Math.sqrt(dx * dx + dy * dy); const spiral = angle + distance * 0.1 - this.frameCount * 0.1; if (Math.sin(spiral * 3) > 0.7) { const char = 'โ—'; const hue = (distance * 10 + this.frameCount) % 360; line += chalk.hsl(hue, 100, 50)(char); } else { line += ' '; } } output += line + '\n'; } output += gradient.vice(`๐ŸŒ€ SPIRAL MODE ๐ŸŒ€ Down the rabbit hole we go!`); process.stdout.write(output); } drunkMode() { this.clear(); let output = ''; // Drunk text effect const text = "EVERYTHING IS WOBBLY AND WEIRD!!!"; for (let row = 0; row < this.height - 2; row++) { let line = ''; for (let col = 0; col < this.width; col++) { const wobble = Math.sin((col + row + this.frameCount) * 0.3) * 2; const charIndex = Math.floor((col + wobble) / 3) % text.length; const char = text[charIndex]; if (Math.random() < 0.3) { const colors = ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan']; line += chalk[colors[Math.floor(Math.random() * colors.length)]](char); } else { line += ' '; } } output += line + '\n'; } output += gradient.fruit(`๐Ÿฅด DRUNK MODE ๐Ÿฅด *hic* Everything's spinning!`); process.stdout.write(output); } start() { this.hideCursor(); this.isRunning = true; console.log(chalk.bold.red('\n๐Ÿ”ฅ TERMINAL CHAOS GENERATOR ๐Ÿ”ฅ')); console.log(chalk.yellow('Press 1-8 for different modes, SPACE to pause, Q to quit\n')); const animate = () => { if (this.isRunning) { switch (this.currentMode) { case 'chaos': this.chaosMode(); break; case 'glitch': this.glitchMode(); break; case 'rainbow': this.rainbowMode(); break; case 'dance': this.danceMode(); break; case 'explosion': this.explosionMode(); break; case 'wave': this.waveMode(); break; case 'spiral': this.spiralMode(); break; case 'drunk': this.drunkMode(); break; } this.frameCount++; } if (this.isRunning) { setTimeout(animate, 100); } }; animate(); } stop() { this.isRunning = false; this.showCursor(); this.clear(); console.log(chalk.bold.green('\nโœจ Thanks for experiencing the chaos! โœจ\n')); process.exit(0); } } // Handle command line arguments const args = process.argv.slice(2); const modeIndex = args.indexOf('--mode'); let mode = 'chaos'; if (modeIndex !== -1 && args[modeIndex + 1]) { mode = args[modeIndex + 1]; } const chaos = new TerminalChaosGenerator(); chaos.currentMode = mode; chaos.start(); module.exports = TerminalChaosGenerator;