gunship999 commited on
Commit
d8ccd32
1 Parent(s): 66232de

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +249 -19
index.html CHANGED
@@ -1,19 +1,249 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>3D Passive Doppler Radar</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
8
+ <style>
9
+ body {
10
+ margin: 0;
11
+ background: #000;
12
+ color: #00ff00;
13
+ font-family: monospace;
14
+ overflow: hidden;
15
+ }
16
+
17
+ #container {
18
+ position: relative;
19
+ width: 100vw;
20
+ height: 100vh;
21
+ }
22
+
23
+ #overlay {
24
+ position: absolute;
25
+ top: 10px;
26
+ left: 10px;
27
+ background: rgba(0,0,0,0.7);
28
+ padding: 10px;
29
+ border: 1px solid #00ff00;
30
+ }
31
+
32
+ #frequencyDisplay {
33
+ margin: 10px 0;
34
+ }
35
+
36
+ button {
37
+ background: #000;
38
+ color: #00ff00;
39
+ border: 1px solid #00ff00;
40
+ padding: 5px 10px;
41
+ cursor: pointer;
42
+ margin: 5px;
43
+ }
44
+
45
+ button:hover {
46
+ background: #00ff00;
47
+ color: #000;
48
+ }
49
+
50
+ #spectrum {
51
+ width: 300px;
52
+ height: 100px;
53
+ border: 1px solid #00ff00;
54
+ }
55
+ </style>
56
+ </head>
57
+ <body>
58
+ <div id="container">
59
+ <div id="overlay">
60
+ <button id="startBtn">Start Detection</button>
61
+ <button id="stopBtn">Stop Detection</button>
62
+ <div id="frequencyDisplay">Frequency: 0 Hz</div>
63
+ <div>Objects detected: <span id="objectCount">0</span></div>
64
+ <canvas id="spectrum"></canvas>
65
+ </div>
66
+ </div>
67
+
68
+ <script>
69
+ let scene, camera, renderer, audioContext, analyser, microphone;
70
+ let points = [];
71
+ let isRunning = false;
72
+
73
+ // Initialize Three.js scene
74
+ function initScene() {
75
+ scene = new THREE.Scene();
76
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
77
+ renderer = new THREE.WebGLRenderer();
78
+ renderer.setSize(window.innerWidth, window.innerHeight);
79
+ document.getElementById('container').appendChild(renderer.domElement);
80
+
81
+ // Add grid
82
+ const gridHelper = new THREE.GridHelper(20, 20, 0x00ff00, 0x003300);
83
+ scene.add(gridHelper);
84
+
85
+ // Position camera
86
+ camera.position.z = 15;
87
+ camera.position.y = 10;
88
+ camera.lookAt(0, 0, 0);
89
+
90
+ // Add ambient light
91
+ const ambientLight = new THREE.AmbientLight(0x404040);
92
+ scene.add(ambientLight);
93
+
94
+ // Add directional light
95
+ const directionalLight = new THREE.DirectionalLight(0x00ff00, 0.5);
96
+ directionalLight.position.set(1, 1, 1);
97
+ scene.add(directionalLight);
98
+ }
99
+
100
+ async function initAudio() {
101
+ audioContext = new (window.AudioContext || window.webkitAudioContext)();
102
+ analyser = audioContext.createAnalyser();
103
+ analyser.fftSize = 2048;
104
+
105
+ try {
106
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
107
+ microphone = audioContext.createMediaStreamSource(stream);
108
+ microphone.connect(analyser);
109
+ } catch (err) {
110
+ console.error('Microphone access denied:', err);
111
+ return false;
112
+ }
113
+ return true;
114
+ }
115
+
116
+ function createPoint(position, intensity) {
117
+ const geometry = new THREE.SphereGeometry(0.1, 8, 8);
118
+ const material = new THREE.MeshPhongMaterial({
119
+ color: new THREE.Color(`rgb(0, ${Math.floor(intensity * 255)}, 0)`),
120
+ transparent: true,
121
+ opacity: 0.7
122
+ });
123
+ const point = new THREE.Mesh(geometry, material);
124
+ point.position.copy(position);
125
+ scene.add(point);
126
+ points.push({
127
+ mesh: point,
128
+ lifetime: 100,
129
+ intensity: intensity
130
+ });
131
+ }
132
+
133
+ function updatePoints() {
134
+ for (let i = points.length - 1; i >= 0; i--) {
135
+ points[i].lifetime--;
136
+ points[i].mesh.material.opacity = points[i].lifetime / 100;
137
+
138
+ if (points[i].lifetime <= 0) {
139
+ scene.remove(points[i].mesh);
140
+ points.splice(i, 1);
141
+ }
142
+ }
143
+ }
144
+
145
+ function analyzeAudio() {
146
+ if (!isRunning) return;
147
+
148
+ const bufferLength = analyser.frequencyBinCount;
149
+ const dataArray = new Uint8Array(bufferLength);
150
+ analyser.getByteFrequencyData(dataArray);
151
+
152
+ // Update spectrum visualization
153
+ const spectrumCanvas = document.getElementById('spectrum');
154
+ const spectrumCtx = spectrumCanvas.getContext('2d');
155
+ spectrumCtx.fillStyle = 'black';
156
+ spectrumCtx.fillRect(0, 0, spectrumCanvas.width, spectrumCanvas.height);
157
+
158
+ const barWidth = spectrumCanvas.width / bufferLength;
159
+ let x = 0;
160
+
161
+ for (let i = 0; i < bufferLength; i++) {
162
+ const barHeight = dataArray[i] * spectrumCanvas.height / 255;
163
+ spectrumCtx.fillStyle = `rgb(0, ${dataArray[i]}, 0)`;
164
+ spectrumCtx.fillRect(x, spectrumCanvas.height - barHeight, barWidth, barHeight);
165
+ x += barWidth;
166
+
167
+ // Create 3D points based on frequency intensity
168
+ if (dataArray[i] > 100) {
169
+ const angle = (Math.PI * 2 * i) / bufferLength;
170
+ const radius = (dataArray[i] / 255) * 10;
171
+ const x = Math.cos(angle) * radius;
172
+ const z = Math.sin(angle) * radius;
173
+ const y = (dataArray[i] / 255) * 5;
174
+
175
+ createPoint(
176
+ new THREE.Vector3(x, y, z),
177
+ dataArray[i] / 255
178
+ );
179
+ }
180
+ }
181
+
182
+ // Calculate dominant frequency
183
+ let maxIndex = 0;
184
+ let maxValue = 0;
185
+ for (let i = 0; i < bufferLength; i++) {
186
+ if (dataArray[i] > maxValue) {
187
+ maxValue = dataArray[i];
188
+ maxIndex = i;
189
+ }
190
+ }
191
+
192
+ const dominantFrequency = maxIndex * audioContext.sampleRate / (analyser.fftSize * 2);
193
+ document.getElementById('frequencyDisplay').textContent =
194
+ `Frequency: ${Math.round(dominantFrequency)} Hz`;
195
+ document.getElementById('objectCount').textContent = points.length;
196
+
197
+ requestAnimationFrame(analyzeAudio);
198
+ }
199
+
200
+ function animate() {
201
+ requestAnimationFrame(animate);
202
+
203
+ if (isRunning) {
204
+ updatePoints();
205
+ // Rotate camera slowly
206
+ camera.position.x = Math.sin(Date.now() * 0.001) * 15;
207
+ camera.position.z = Math.cos(Date.now() * 0.001) * 15;
208
+ camera.lookAt(0, 0, 0);
209
+ }
210
+
211
+ renderer.render(scene, camera);
212
+ }
213
+
214
+ async function startDetection() {
215
+ if (!audioContext && !(await initAudio())) return;
216
+ isRunning = true;
217
+ analyzeAudio();
218
+ }
219
+
220
+ function stopDetection() {
221
+ isRunning = false;
222
+ if (microphone) {
223
+ microphone.disconnect();
224
+ microphone = null;
225
+ }
226
+ if (audioContext) {
227
+ audioContext.close();
228
+ audioContext = null;
229
+ }
230
+ // Clear all points
231
+ points.forEach(point => scene.remove(point.mesh));
232
+ points = [];
233
+ }
234
+
235
+ // Event listeners
236
+ document.getElementById('startBtn').addEventListener('click', startDetection);
237
+ document.getElementById('stopBtn').addEventListener('click', stopDetection);
238
+ window.addEventListener('resize', () => {
239
+ camera.aspect = window.innerWidth / window.innerHeight;
240
+ camera.updateProjectionMatrix();
241
+ renderer.setSize(window.innerWidth, window.innerHeight);
242
+ });
243
+
244
+ // Initialize and start animation
245
+ initScene();
246
+ animate();
247
+ </script>
248
+ </body>
249
+ </html><script async data-explicit-opt-in="true" data-cookie-opt-in="true" src="https://vercel.live/_next-live/feedback/feedback.js"></script>