-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvqfc.html
101 lines (94 loc) · 3.62 KB
/
vqfc.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quantum Flute Chatbot</title>
<style>
body {
font-family: 'Times New Roman', serif;
background-color: #ffffff;
color: #000000;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
padding: 10px;
}
#controls input[type="text"] {
width: 50%;
margin-bottom: 10px;
}
#controls input[type="range"] {
width: 50%;
}
pre {
margin-top: 20px;
font-size: 1.1em;
border: 1px solid #000000;
padding: 10px;
max-width: 90%;
word-wrap: break-word;
}
</style>
</head>
<body>
<div id="controls">
<input type="text" id="user-query" onkeydown="if(event.keyCode === 13) processQuery(this.value)">
<input type="range" min="0.5" max="1.5" step="0.01" value="1" oninput="updateModulation(this.value)" role="slider" aria-label="Modulation Factor" />
</div>
<pre id="quantum-output"></pre>
<script>
(function() {
if (!window.AudioContext && !window.webkitAudioContext) {
alert('Your browser does not support the Web Audio API');
return;
}
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const gainNode = audioContext.createGain();
let modulationFactor = 1;
let currentQuery = '';
let isLooping = false;
window.processQuery = function(query) {
if(query !== currentQuery) {
currentQuery = query;
isLooping = true;
}
if (isLooping) {
gainNode.connect(audioContext.destination);
const quantumStates = mapQueryToQuantumStates(currentQuery);
displayQuantumOutput(quantumStates);
playQuantumSound(quantumStates);
setTimeout(() => processQuery(currentQuery), (quantumStates.length * 0.4 + 0.4) * 1000);
}
}
window.stopLoop = function() {
isLooping = false;
}
function mapQueryToQuantumStates(query) {
return Array.from(query, char => char.charCodeAt(0) % 3);
}
function displayQuantumOutput(states) {
const outputElement = document.getElementById('quantum-output');
const asciiArt = states.map(state => state === 0 ? '1' : state === 1 ? '2' : '0');
outputElement.textContent = asciiArt.join(' ');
}
function playQuantumSound(states) {
states.forEach((state, index) => {
const oscillator = audioContext.createOscillator();
oscillator.frequency.setValueAtTime((440 + state * 110) * modulationFactor, audioContext.currentTime);
oscillator.connect(gainNode);
oscillator.start(audioContext.currentTime + index * 0.4);
oscillator.stop(audioContext.currentTime + index * 0.4 + 0.4);
});
}
window.updateModulation = function(value) {
modulationFactor = value;
gainNode.gain.value = Math.exp(value - 1);
}
})();
</script>
</body>
</html>