Changed around line 1
+ class Visualizer {
+ constructor() {
+ this.canvas = document.getElementById('visualizer');
+ this.ctx = this.canvas.getContext('2d');
+ this.isPlaying = false;
+ this.currentStyle = 'bars';
+ this.bars = 60;
+ this.setupCanvas();
+ this.setupEventListeners();
+ this.animate();
+ }
+
+ setupCanvas() {
+ this.canvas.width = 800;
+ this.canvas.height = 450;
+ }
+
+ setupEventListeners() {
+ window.addEventListener('resize', () => this.setupCanvas());
+ document.getElementById('playBtn').addEventListener('click', () => {
+ this.isPlaying = !this.isPlaying;
+ document.querySelector('.play-icon').textContent = this.isPlaying ? '⏸' : '▶';
+ });
+ document.getElementById('visualStyle').addEventListener('change', (e) => {
+ this.currentStyle = e.target.value;
+ });
+ }
+
+ drawBars() {
+ const width = this.canvas.width / this.bars;
+ for (let i = 0; i < this.bars; i++) {
+ const height = this.isPlaying ? Math.random() * this.canvas.height * 0.8 : 5;
+ const hue = (i / this.bars) * 360;
+ this.ctx.fillStyle = `hsla(${hue}, 80%, 50%, 0.8)`;
+ this.ctx.fillRect(
+ i * width,
+ this.canvas.height - height,
+ width - 1,
+ height
+ );
+ }
+ }
+
+ drawWaves() {
+ this.ctx.beginPath();
+ this.ctx.moveTo(0, this.canvas.height / 2);
+ for (let i = 0; i < this.canvas.width; i++) {
+ const amplitude = this.isPlaying ? Math.random() * 100 : 20;
+ const y = this.canvas.height/2 + Math.sin(i * 0.02 + Date.now() * 0.002) * amplitude;
+ this.ctx.lineTo(i, y);
+ }
+ this.ctx.strokeStyle = `hsl(${Date.now() * 0.05 % 360}, 80%, 50%)`;
+ this.ctx.lineWidth = 2;
+ this.ctx.stroke();
+ }
+
+ drawSpectrum() {
+ const centerX = this.canvas.width / 2;
+ const centerY = this.canvas.height / 2;
+ const radius = Math.min(centerX, centerY) * 0.8;
+ const particles = 200;
+
+ for (let i = 0; i < particles; i++) {
+ const angle = (i / particles) * Math.PI * 2;
+ const amplitude = this.isPlaying ? 0.3 + Math.random() * 0.7 : 0.5;
+ const x = centerX + Math.cos(angle) * radius * amplitude;
+ const y = centerY + Math.sin(angle) * radius * amplitude;
+ const hue = (i / particles) * 360;
+
+ this.ctx.beginPath();
+ this.ctx.arc(x, y, 2, 0, Math.PI * 2);
+ this.ctx.fillStyle = `hsla(${hue}, 80%, 50%, 0.8)`;
+ this.ctx.fill();
+ }
+ }
+
+ animate() {
+ this.ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
+
+ switch(this.currentStyle) {
+ case 'bars':
+ this.drawBars();
+ break;
+ case 'waves':
+ this.drawWaves();
+ break;
+ case 'spectrum':
+ this.drawSpectrum();
+ break;
+ }
+
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new Visualizer();
+ });