-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegible.html
379 lines (333 loc) · 11.8 KB
/
legible.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Terminal-Like Visualizer with Datamuse API</title>
<!-- Particles.js Library -->
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
color: #00ff00;
font-family: 'Courier New', monospace;
overflow: hidden;
}
#particles-js {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
}
.grid {
display: grid;
width: 90vw;
height: 80vh;
gap: 1px;
grid-template-columns: repeat(30, 1fr);
grid-template-rows: repeat(15, 1fr);
transform-origin: center;
transition: transform 0.3s ease;
z-index: 1;
}
.cell {
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5vw;
color: #00ff00;
background: #001a00;
transition: all 0.3s ease;
}
.controls {
position: absolute;
top: 10px;
left: 10px;
display: flex;
flex-direction: column;
gap: 10px;
z-index: 1000;
}
button, label, input, select {
font-size: 16px;
color: #00ff00;
background-color: #111;
border: 1px solid #00ff00;
padding: 5px 10px;
}
button {
cursor: pointer;
}
button:hover, select:hover {
background-color: #002200;
}
input[type="range"] {
width: 100%;
}
@keyframes dissolve {
0% {
opacity: 1;
filter: drop-shadow(0 0 10px #00ff00);
}
100% {
opacity: 0;
transform: scale(0.8);
}
}
@keyframes flicker {
0% { opacity: 1; }
50% { opacity: 0.7; }
100% { opacity: 1; }
}
.flicker {
animation: flicker 0.5s infinite;
}
@media (max-width: 768px) {
.cell {
font-size: 3vw;
}
}
@media (min-width: 769px) {
.cell {
font-size: 1.5vw;
}
}
</style>
</head>
<body>
<div class="controls">
<button id="start-button">Start Microphone</button>
<label for="sensitivity">Beat Sensitivity:</label>
<input id="sensitivity" type="range" min="0.1" max="1" step="0.05" value="0.3">
<label for="color-scheme">Color Scheme:</label>
<select id="color-scheme">
<option value="matrix">Matrix</option>
<option value="cyberpunk">Cyberpunk</option>
<option value="retro">Retro</option>
<option value="rainforest">Rainforest</option>
<option value="desert">Desert</option>
<option value="arctic">Arctic</option>
<option value="coral_reef">Coral Reef</option>
<option value="earlyComputers">Early Computers</option>
<option value="dos">DOS</option>
<option value="windows95">Windows 95</option>
<option value="modernIDE">Modern IDE</option>
</select>
<button id="reset-button">Reset Grid</button>
</div>
<div id="particles-js"></div>
<div class="grid" id="grid"></div>
<script>
let audioContext, analyser, dataArray, micStream, isMicrophoneEnabled = false;
const startButton = document.getElementById('start-button');
const resetButton = document.getElementById('reset-button');
const sensitivitySlider = document.getElementById('sensitivity');
const colorSchemeSelect = document.getElementById('color-scheme');
let sensitivity = parseFloat(sensitivitySlider.value);
let wordIndex = 0;
let cyclingActive = true;
const gridElement = document.getElementById('grid');
let words = [];
let revealedLocations = [];
// Fetch words using the Datamuse API
async function fetchWords() {
try {
const response = await fetch('https://api.datamuse.com/words?ml=visual&max=100');
if (response.ok) {
const wordObjects = await response.json();
words = wordObjects.map(wordObj => wordObj.word.toUpperCase());
} else {
console.error('Failed to fetch words. Using default words.');
words = 'HELLO WORLD FROM A COOL TERMINAL VISUALIZER SYSTEM SIMULATION'.split(' ');
}
} catch (error) {
console.error('Error fetching words:', error);
words = 'HELLO WORLD FROM A COOL TERMINAL VISUALIZER SYSTEM SIMULATION'.split(' ');
}
}
fetchWords();
sensitivitySlider.addEventListener('input', () => {
sensitivity = parseFloat(sensitivitySlider.value);
});
startButton.addEventListener('click', startMicAudio);
resetButton.addEventListener('click', resetGrid);
colorSchemeSelect.addEventListener('change', updateColorScheme);
// Particles.js configuration
particlesJS("particles-js", {
particles: {
number: { value: 80, density: { enable: true, value_area: 800 } },
color: { value: "#00ff00" },
shape: { type: "circle" },
opacity: { value: 0.5, random: false },
size: { value: 3, random: true },
line_linked: { enable: true, distance: 150, color: "#00ff00", opacity: 0.4, width: 1 },
move: { enable: true, speed: 2, direction: "none", random: false, straight: false, out_mode: "out" }
},
interactivity: {
detect_on: "canvas",
events: { onhover: { enable: true, mode: "repulse" }, onclick: { enable: true, mode: "push" } },
modes: { repulse: { distance: 100, duration: 0.4 }, push: { particles_nb: 4 } }
},
retina_detect: true
});
function updateColorScheme() {
const scheme = colorSchemeSelect.value;
const colorSchemes = {
matrix: { primary: '#00ff00', secondary: '#001a00' },
cyberpunk: { primary: '#ff00ff', secondary: '#000033' },
retro: { primary: '#ffff00', secondary: '#330000' },
rainforest: { primary: '#228B22', secondary: '#32CD32' },
desert: { primary: '#DEB887', secondary: '#F4A460' },
arctic: { primary: '#F0F8FF', secondary: '#87CEFA' },
coral_reef: { primary: '#00CED1', secondary: '#FF7F50' },
earlyComputers: { primary: '#00FF00', secondary: '#000000' },
dos: { primary: '#FFFFFF', secondary: '#0000AA' },
windows95: { primary: '#C0C0C0', secondary: '#000080' },
modernIDE: { primary: '#1E1E1E', secondary: '#D4D4D4' }
};
const selectedScheme = colorSchemes[scheme];
document.querySelectorAll('.cell').forEach(cell => {
cell.style.color = selectedScheme.primary;
cell.style.background = selectedScheme.secondary;
});
// Update particle color
updateParticleColor(selectedScheme.primary);
}
// Update particle color based on selected scheme
function updateParticleColor(color) {
pJSDom[0].pJS.particles.color.value = color;
pJSDom[0].pJS.particles.line_linked.color = color;
pJSDom[0].pJS.fn.particlesRefresh();
}
// Initialize the grid with cells and start random character cycling
function generateGibberishGrid() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
gridElement.innerHTML = ''; // Clear the grid before regenerating
const fragment = document.createDocumentFragment();
for (let i = 0; i < 450; i++) { // Fixed number of cells for better performance
const cell = document.createElement('div');
cell.classList.add('cell');
cell.textContent = chars.charAt(Math.floor(Math.random() * chars.length));
fragment.appendChild(cell);
}
gridElement.appendChild(fragment);
}
generateGibberishGrid();
// Start random character cycling for all grid cells
function cycleRandomCharacters() {
const gridCells = document.querySelectorAll('.cell');
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function updateCharacters() {
if (cyclingActive) {
gridCells.forEach(cell => {
if (!cell.dataset.fixed) {
cell.textContent = chars.charAt(Math.floor(Math.random() * chars.length));
}
});
setTimeout(updateCharacters, 100); // Use setTimeout to avoid overwhelming the browser
}
}
updateCharacters();
}
cycleRandomCharacters(); // Start cycling the characters
function startMicAudio() {
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(stream => {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioContext.createAnalyser();
analyser.fftSize = 512;
dataArray = new Uint8Array(analyser.frequencyBinCount);
micStream = audioContext.createMediaStreamSource(stream);
micStream.connect(analyser);
isMicrophoneEnabled = true;
startButton.textContent = 'Microphone Active';
startButton.disabled = true;
render(); // Start the visualizer
})
.catch(err => {
alert('Microphone access denied. Please allow microphone access to enable the visualizer.');
});
}
function getBeat() {
analyser.getByteFrequencyData(dataArray);
let sumLow = 0;
const lowEnd = Math.floor(dataArray.length * 0.2);
for (let i = 0; i < lowEnd; i++) {
sumLow += dataArray[i];
}
return (sumLow / lowEnd) / 255; // Return normalized beat strength for the low range
}
function revealWordAtRandomLocation() {
if (wordIndex < words.length) {
const word = words[wordIndex];
const gridCells = document.querySelectorAll('.cell');
const maxCol = Math.sqrt(gridCells.length) - word.length;
let randomIndex;
do {
randomIndex = Math.floor(Math.random() * (gridCells.length - word.length));
} while (isOverlap(randomIndex, word.length));
const wordElements = [];
for (let i = 0; i < word.length; i++) {
const cell = gridCells[randomIndex + i];
cell.textContent = word[i];
cell.dataset.fixed = true;
cell.classList.add("flicker");
wordElements.push(cell);
}
revealedLocations.push({ index: randomIndex, length: word.length });
wordElements.forEach(cell => {
cell.addEventListener('click', () => dissolveWord(wordElements));
});
wordIndex++;
}
}
function isOverlap(index, length) {
for (let location of revealedLocations) {
if (index < location.index + location.length && index + length > location.index) {
return true;
}
}
return false;
}
function dissolveWord(wordElements) {
wordElements.forEach(cell => {
cell.style.animation = 'dissolve 0.8s forwards';
cell.addEventListener('animationend', () => {
cell.textContent = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.charAt(Math.floor(Math.random() * 26)); // Revert to gibberish
cell.classList.remove('flicker');
delete cell.dataset.fixed; // Allow it to cycle again
});
});
}
function resetGrid() {
generateGibberishGrid();
revealedLocations = [];
wordIndex = 0;
updateColorScheme();
cycleRandomCharacters(); // Restart cycling after reset
}
function render(time) {
requestAnimationFrame(render);
if (isMicrophoneEnabled) {
const beatStrength = getBeat();
if (beatStrength > sensitivity) {
revealWordAtRandomLocation();
gridElement.style.transform = `scale(${1 + beatStrength * 0.1})`;
} else {
gridElement.style.transform = 'scale(1)';
}
}
}
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
alert('Your browser does not support microphone access. Please update to a modern browser.');
}
// Initialize color scheme
updateColorScheme();
</script>
</body>
</html>