AdityaAdaki commited on
Commit
054ccac
·
1 Parent(s): ece710d

css update

Browse files
Files changed (2) hide show
  1. static/css/style.css +1 -1
  2. static/js/main.js +151 -37
static/css/style.css CHANGED
@@ -892,7 +892,7 @@ input[type="file"] {
892
  .viz-type-dropdown {
893
  position: fixed;
894
  top: 60px;
895
- right: -200px;
896
  background: var(--surface-color);
897
  backdrop-filter: blur(12px);
898
  border-radius: 8px;
 
892
  .viz-type-dropdown {
893
  position: fixed;
894
  top: 60px;
895
+ right: -220px;
896
  background: var(--surface-color);
897
  backdrop-filter: blur(12px);
898
  border-radius: 8px;
static/js/main.js CHANGED
@@ -30,6 +30,22 @@ let visualizers = {
30
  let isShuffleActive = false;
31
  let isRepeatActive = false;
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  // Theme button functionality
34
  const themeBtn = document.querySelector('.theme-btn');
35
  if (themeBtn) {
@@ -66,59 +82,107 @@ function initAudio() {
66
  // Visualization creation functions
67
  function createBarsVisualization() {
68
  const geometry = new THREE.BoxGeometry(0.1, 1, 0.1);
69
- const material = new THREE.MeshPhongMaterial({ color: 0x4CAF50 });
70
- const numBars = 64;
 
 
 
 
71
 
72
  for (let i = 0; i < numBars; i++) {
 
73
  const bar = new THREE.Mesh(geometry, material);
74
  const angle = (i / numBars) * Math.PI * 2;
75
- bar.position.x = Math.cos(angle) * 2;
76
- bar.position.z = Math.sin(angle) * 2;
 
 
 
77
  scene.add(bar);
78
  visualizers.bars.push(bar);
79
  }
80
 
81
- // Add lighting
82
- const light = new THREE.PointLight(0xffffff, 1, 100);
83
  light.position.set(0, 5, 0);
84
  scene.add(light);
85
 
86
- const ambientLight = new THREE.AmbientLight(0x404040);
87
  scene.add(ambientLight);
88
  }
89
 
90
  function createSphereVisualization() {
91
- const geometry = new THREE.SphereGeometry(1, 32, 32);
92
  const material = new THREE.MeshPhongMaterial({
93
  color: 0x4CAF50,
94
- wireframe: true
 
 
 
95
  });
96
  visualizers.sphere = new THREE.Mesh(geometry, material);
 
 
 
 
 
97
  scene.add(visualizers.sphere);
98
 
99
- // Add lighting
100
- const light = new THREE.PointLight(0xffffff, 1, 100);
101
- light.position.set(0, 5, 0);
102
- scene.add(light);
 
 
 
 
103
  }
104
 
105
  function createParticlesVisualization() {
106
- const particleCount = 1000;
107
  const geometry = new THREE.BufferGeometry();
108
  const positions = new Float32Array(particleCount * 3);
 
 
 
 
 
 
109
 
110
  for (let i = 0; i < particleCount * 3; i += 3) {
111
- positions[i] = (Math.random() - 0.5) * 3;
112
- positions[i + 1] = (Math.random() - 0.5) * 3;
113
- positions[i + 2] = (Math.random() - 0.5) * 3;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
 
116
  geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
 
 
117
 
118
  const material = new THREE.PointsMaterial({
119
- color: 0x4CAF50,
120
- size: 0.05,
121
- transparent: true
 
 
122
  });
123
 
124
  visualizers.particles = new THREE.Points(geometry, material);
@@ -127,44 +191,91 @@ function createParticlesVisualization() {
127
 
128
  // Visualization update functions
129
  function updateBarsVisualization(dataArray) {
130
- const multiplier = 0.01;
 
 
131
  visualizers.bars.forEach((bar, i) => {
132
  const value = dataArray[i] * multiplier;
 
 
133
  bar.scale.y = value + 0.1;
134
- bar.position.y = value / 2;
 
 
 
 
 
 
 
135
  });
136
  }
137
 
138
  function updateSphereVisualization(dataArray) {
139
  if (!visualizers.sphere) return;
140
 
141
- const averageFrequency = dataArray.reduce((a, b) => a + b) / dataArray.length;
142
- const scale = 1 + (averageFrequency * 0.003);
143
- visualizers.sphere.scale.set(scale, scale, scale);
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  visualizers.sphere.rotation.y += 0.01;
 
 
 
 
 
 
145
  }
146
 
147
  function updateParticlesVisualization(dataArray) {
148
  if (!visualizers.particles) return;
149
 
150
  const positions = visualizers.particles.geometry.attributes.position.array;
151
- const multiplier = 0.02;
 
 
152
 
153
  for (let i = 0; i < positions.length; i += 3) {
154
- const value = dataArray[i / 3] * multiplier;
155
- const distance = Math.sqrt(
156
- positions[i] * positions[i] +
157
- positions[i + 1] * positions[i + 1] +
158
- positions[i + 2] * positions[i + 2]
159
- );
 
 
 
 
160
 
161
- positions[i] *= 1 + (value / distance);
162
- positions[i + 1] *= 1 + (value / distance);
163
- positions[i + 2] *= 1 + (value / distance);
 
 
 
 
 
 
164
  }
165
 
166
  visualizers.particles.geometry.attributes.position.needsUpdate = true;
 
 
 
 
167
  visualizers.particles.rotation.y += 0.001;
 
168
  }
169
 
170
  // Animation loop
@@ -210,8 +321,8 @@ function setupOrbitControls() {
210
  controls.dampingFactor = 0.05;
211
  controls.enableZoom = true;
212
  controls.autoRotate = true;
213
- controls.autoRotateSpeed = 2.0;
214
- camera.position.z = 5;
215
  }
216
 
217
  // Handle file uploads
@@ -473,6 +584,9 @@ function createVisualization() {
473
  particles: null
474
  };
475
 
 
 
 
476
  switch(visualizationType) {
477
  case 'bars':
478
  createBarsVisualization();
 
30
  let isShuffleActive = false;
31
  let isRepeatActive = false;
32
 
33
+ // Add visualization-specific camera positions
34
+ const visualizerSettings = {
35
+ bars: {
36
+ cameraZ: 8,
37
+ baseRadius: 2
38
+ },
39
+ sphere: {
40
+ cameraZ: 5,
41
+ baseRadius: 1
42
+ },
43
+ particles: {
44
+ cameraZ: 20,
45
+ baseRadius: 8
46
+ }
47
+ };
48
+
49
  // Theme button functionality
50
  const themeBtn = document.querySelector('.theme-btn');
51
  if (themeBtn) {
 
82
  // Visualization creation functions
83
  function createBarsVisualization() {
84
  const geometry = new THREE.BoxGeometry(0.1, 1, 0.1);
85
+ const numBars = 128;
86
+ const materials = [
87
+ new THREE.MeshPhongMaterial({ color: 0x4CAF50 }),
88
+ new THREE.MeshPhongMaterial({ color: 0x2196F3 }),
89
+ new THREE.MeshPhongMaterial({ color: 0xFF4081 })
90
+ ];
91
 
92
  for (let i = 0; i < numBars; i++) {
93
+ const material = materials[i % materials.length];
94
  const bar = new THREE.Mesh(geometry, material);
95
  const angle = (i / numBars) * Math.PI * 2;
96
+ const radius = 2;
97
+ bar.position.x = Math.cos(angle) * radius;
98
+ bar.position.z = Math.sin(angle) * radius;
99
+ bar.userData.initialY = bar.position.y;
100
+ bar.userData.phase = i * 0.1;
101
  scene.add(bar);
102
  visualizers.bars.push(bar);
103
  }
104
 
105
+ // Enhanced lighting
106
+ const light = new THREE.PointLight(0xffffff, 1.5, 100);
107
  light.position.set(0, 5, 0);
108
  scene.add(light);
109
 
110
+ const ambientLight = new THREE.AmbientLight(0x404040, 0.5);
111
  scene.add(ambientLight);
112
  }
113
 
114
  function createSphereVisualization() {
115
+ const geometry = new THREE.IcosahedronGeometry(1, 4);
116
  const material = new THREE.MeshPhongMaterial({
117
  color: 0x4CAF50,
118
+ wireframe: true,
119
+ emissive: 0x2196F3,
120
+ emissiveIntensity: 0.5,
121
+ shininess: 50
122
  });
123
  visualizers.sphere = new THREE.Mesh(geometry, material);
124
+
125
+ // Store original vertex positions
126
+ visualizers.sphere.userData.originalPositions =
127
+ geometry.attributes.position.array.slice();
128
+
129
  scene.add(visualizers.sphere);
130
 
131
+ // Enhanced lighting
132
+ const light1 = new THREE.PointLight(0xFF4081, 1, 100);
133
+ light1.position.set(5, 5, 5);
134
+ scene.add(light1);
135
+
136
+ const light2 = new THREE.PointLight(0x2196F3, 1, 100);
137
+ light2.position.set(-5, -5, -5);
138
+ scene.add(light2);
139
  }
140
 
141
  function createParticlesVisualization() {
142
+ const particleCount = 2000;
143
  const geometry = new THREE.BufferGeometry();
144
  const positions = new Float32Array(particleCount * 3);
145
+ const colors = new Float32Array(particleCount * 3);
146
+ const sizes = new Float32Array(particleCount);
147
+
148
+ const color1 = new THREE.Color(0x4CAF50);
149
+ const color2 = new THREE.Color(0x2196F3);
150
+ const color3 = new THREE.Color(0xFF4081);
151
 
152
  for (let i = 0; i < particleCount * 3; i += 3) {
153
+ // Create spiral pattern with larger radius
154
+ const angle = (i / particleCount) * Math.PI * 8;
155
+ const radius = (Math.random() * 4) + 2;
156
+
157
+ positions[i] = Math.cos(angle) * radius;
158
+ positions[i + 1] = (Math.random() - 0.5) * 6;
159
+ positions[i + 2] = Math.sin(angle) * radius;
160
+
161
+ // Interpolate between colors based on position
162
+ const colorMix = Math.abs(Math.sin(angle));
163
+ const finalColor = new THREE.Color().lerpColors(
164
+ color1,
165
+ colorMix > 0.5 ? color2 : color3,
166
+ colorMix
167
+ );
168
+
169
+ colors[i] = finalColor.r;
170
+ colors[i + 1] = finalColor.g;
171
+ colors[i + 2] = finalColor.b;
172
+
173
+ sizes[i / 3] = Math.random() * 0.1 + 0.05;
174
  }
175
 
176
  geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
177
+ geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
178
+ geometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
179
 
180
  const material = new THREE.PointsMaterial({
181
+ size: 0.15,
182
+ vertexColors: true,
183
+ transparent: true,
184
+ opacity: 0.8,
185
+ blending: THREE.AdditiveBlending
186
  });
187
 
188
  visualizers.particles = new THREE.Points(geometry, material);
 
191
 
192
  // Visualization update functions
193
  function updateBarsVisualization(dataArray) {
194
+ const time = Date.now() * 0.001;
195
+ const multiplier = 0.015;
196
+
197
  visualizers.bars.forEach((bar, i) => {
198
  const value = dataArray[i] * multiplier;
199
+ // Add wave effect
200
+ const wave = Math.sin(time * 2 + bar.userData.phase) * 0.1;
201
  bar.scale.y = value + 0.1;
202
+ bar.position.y = (value / 2) + wave;
203
+
204
+ // Rotate bars based on audio
205
+ bar.rotation.y = time * 0.1 + (value * 0.1);
206
+
207
+ // Update bar color based on frequency
208
+ const hue = (i / visualizers.bars.length) + (time * 0.1);
209
+ bar.material.color.setHSL(hue, 0.7, 0.5);
210
  });
211
  }
212
 
213
  function updateSphereVisualization(dataArray) {
214
  if (!visualizers.sphere) return;
215
 
216
+ const positions = visualizers.sphere.geometry.attributes.position.array;
217
+ const originalPositions = visualizers.sphere.userData.originalPositions;
218
+ const time = Date.now() * 0.001;
219
+
220
+ for (let i = 0; i < positions.length; i += 3) {
221
+ const i3 = i / 3;
222
+ const value = dataArray[i3 % dataArray.length] / 255;
223
+
224
+ // Create complex deformation
225
+ const deform = value * 0.5;
226
+ positions[i] = originalPositions[i] * (1 + deform * Math.sin(time + i3));
227
+ positions[i + 1] = originalPositions[i + 1] * (1 + deform * Math.cos(time + i3));
228
+ positions[i + 2] = originalPositions[i + 2] * (1 + deform * Math.sin(time * 0.5 + i3));
229
+ }
230
+
231
+ visualizers.sphere.geometry.attributes.position.needsUpdate = true;
232
  visualizers.sphere.rotation.y += 0.01;
233
+ visualizers.sphere.rotation.x += 0.005;
234
+
235
+ // Update material colors
236
+ const hue = (Math.sin(time * 0.1) + 1) * 0.5;
237
+ visualizers.sphere.material.color.setHSL(hue, 0.7, 0.5);
238
+ visualizers.sphere.material.emissive.setHSL((hue + 0.5) % 1, 0.7, 0.3);
239
  }
240
 
241
  function updateParticlesVisualization(dataArray) {
242
  if (!visualizers.particles) return;
243
 
244
  const positions = visualizers.particles.geometry.attributes.position.array;
245
+ const colors = visualizers.particles.geometry.attributes.color.array;
246
+ const sizes = visualizers.particles.geometry.attributes.size.array;
247
+ const time = Date.now() * 0.001;
248
 
249
  for (let i = 0; i < positions.length; i += 3) {
250
+ const i3 = i / 3;
251
+ const value = dataArray[i3 % dataArray.length] / 255;
252
+
253
+ // Keep consistent radius while rotating
254
+ const angle = (i3 / positions.length) * Math.PI * 8 + time;
255
+ const baseRadius = 8; // Fixed base radius
256
+
257
+ positions[i] = Math.cos(angle) * baseRadius;
258
+ positions[i + 1] += (Math.random() - 0.5) * 0.15;
259
+ positions[i + 2] = Math.sin(angle) * baseRadius;
260
 
261
+ // Update colors based on audio and position
262
+ const hue = (angle / (Math.PI * 2)) + time * 0.1;
263
+ const color = new THREE.Color().setHSL(hue, 0.7, 0.5 + value * 0.5);
264
+ colors[i] = color.r;
265
+ colors[i + 1] = color.g;
266
+ colors[i + 2] = color.b;
267
+
268
+ // Update particle sizes with audio reactivity
269
+ sizes[i3] = (value * 0.3 + 0.08) * (1 + Math.sin(time + i3) * 0.2);
270
  }
271
 
272
  visualizers.particles.geometry.attributes.position.needsUpdate = true;
273
+ visualizers.particles.geometry.attributes.color.needsUpdate = true;
274
+ visualizers.particles.geometry.attributes.size.needsUpdate = true;
275
+
276
+ // Rotate the entire particle system
277
  visualizers.particles.rotation.y += 0.001;
278
+ visualizers.particles.rotation.x += 0.0005;
279
  }
280
 
281
  // Animation loop
 
321
  controls.dampingFactor = 0.05;
322
  controls.enableZoom = true;
323
  controls.autoRotate = true;
324
+ controls.autoRotateSpeed = 1.5;
325
+ // Camera position is now set in createVisualization
326
  }
327
 
328
  // Handle file uploads
 
584
  particles: null
585
  };
586
 
587
+ // Set camera position based on visualization type
588
+ camera.position.z = visualizerSettings[visualizationType].cameraZ;
589
+
590
  switch(visualizationType) {
591
  case 'bars':
592
  createBarsVisualization();