File size: 7,157 Bytes
54e0bd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78e24fa
54e0bd9
 
 
 
 
 
 
 
 
 
 
 
78e24fa
54e0bd9
 
 
78e24fa
 
 
 
 
 
54e0bd9
 
 
 
78e24fa
54e0bd9
 
 
 
78e24fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54e0bd9
78e24fa
54e0bd9
 
 
 
 
 
 
 
 
78e24fa
 
 
 
 
 
 
 
 
 
54e0bd9
78e24fa
 
 
54e0bd9
 
 
78e24fa
54e0bd9
 
 
 
78e24fa
54e0bd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Quantum Particle Field Animation
class QuantumParticleField {
    constructor() {
        this.canvas = document.getElementById('quantum-canvas');
        this.ctx = this.canvas.getContext('2d');
        this.particles = [];
        this.connections = [];
        this.mouse = { x: 0, y: 0 };
        
        this.init();
        this.animate();
        this.setupEventListeners();
    }

    init() {
        this.resizeCanvas();
        this.createParticles();
    }

    resizeCanvas() {
        this.canvas.width = window.innerWidth;
        this.canvas.height = window.innerHeight;
    }
    createParticles() {
        const particleCount = Math.min(100, Math.floor(window.innerWidth * window.innerHeight / 15000));
        this.particles = [];

        const colors = [
            { r: 6, g: 182, b: 212 },   // Cyan
            { r: 59, g: 130, b: 246 },  // Blue
            { r: 139, g: 92, b: 246 },  // Purple
            { r: 236, g: 72, b: 153 },  // Pink
            { r: 249, g: 115, b: 22 }   // Orange
        ];

        for (let i = 0; i < particleCount; i++) {
            const color = colors[Math.floor(Math.random() * colors.length)];
            const alpha = Math.random() * 0.6 + 0.4; // Higher opacity for better visibility
            this.particles.push({
                x: Math.random() * this.canvas.width,
                y: Math.random() * this.canvas.height,
                vx: (Math.random() - 0.5) * 0.3, // Slower movement
                vy: (Math.random() - 0.5) * 0.3,
                radius: Math.random() * 4 + 2, // Larger particles
                color: `rgba(${color.r}, ${color.g}, ${color.b}, ${alpha})`,
                originalRadius: Math.random() * 4 + 2,
                glow: Math.random() * 0.8 + 0.7, // Stronger glow
                connections: []
            });
        }
    }
drawParticles() {
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
        
        // Draw connections first
        this.drawConnections();
            // Draw particles
            this.particles.forEach(particle => {
                this.ctx.beginPath();
                this.ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
                
                // Enhanced glowing effect with stronger visibility
                const gradient = this.ctx.createRadialGradient(
                    particle.x, particle.y, 0,
                    particle.x, particle.y, particle.radius * 4
                );
                gradient.addColorStop(0, particle.color.replace(')', ', 1)').replace('rgba', 'rgb'));
                gradient.addColorStop(0.3, particle.color);
                gradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
                
                this.ctx.fillStyle = gradient;
                this.ctx.fill();
                
                // Add outer glow
                this.ctx.beginPath();
                this.ctx.arc(particle.x, particle.y, particle.radius * 3, 0, Math.PI * 2);
                const outerGradient = this.ctx.createRadialGradient(
                    particle.x, particle.y, particle.radius,
                    particle.x, particle.y, particle.radius * 3
                );
                outerGradient.addColorStop(0, particle.color.replace(')', ', 0.3)'));
                outerGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
                this.ctx.fillStyle = outerGradient;
                this.ctx.fill();
                
                // Pulsing effect
                particle.radius = particle.originalRadius + Math.sin(Date.now() * 0.001 + particle.x) * 0.8;
            });
}
    drawConnections() {
        const maxDistance = 120;
        
        for (let i = 0; i < this.particles.length; i++) {
            for (let j = i + 1; j < this.particles.length; j++) {
                const dx = this.particles[i].x - this.particles[j].x;
                const dy = this.particles[i].y - this.particles[j].y;
                const distance = Math.sqrt(dx * dx + dy * dy);
                
                if (distance < maxDistance) {
                    const opacity = 1 - (distance / maxDistance);
                    
                    // Create gradient for connection line
                    const gradient = this.ctx.createLinearGradient(
                        this.particles[i].x, this.particles[i].y,
                        this.particles[j].x, this.particles[j].y
                    );
                    
                    gradient.addColorStop(0, this.particles[i].color);
                    gradient.addColorStop(1, this.particles[j].color);
                    
                    this.ctx.beginPath();
                    this.ctx.strokeStyle = gradient;
                    this.ctx.lineWidth = opacity * 1.5;
                    this.ctx.globalAlpha = opacity * 0.3;
                    this.ctx.moveTo(this.particles[i].x, this.particles[i].y);
                    this.ctx.lineTo(this.particles[j].x, this.particles[j].y);
                    this.ctx.stroke();
                    this.ctx.globalAlpha = 1;
                }
            }
        }
    }
updateParticles() {
        this.particles.forEach(particle => {
            // Move particle
            particle.x += particle.vx;
            particle.y += particle.vy;
            
            // Bounce off walls
            if (particle.x < 0 || particle.x > this.canvas.width) particle.vx *= -1;
            if (particle.y < 0 || particle.y > this.canvas.height) particle.vy *= -1;
            
            // Mouse interaction
            const dx = particle.x - this.mouse.x;
            const dy = particle.y - this.mouse.y;
            const distance = Math.sqrt(dx * dx + dy * dy);
            
            if (distance < 100) {
                const force = (100 - distance) / 100;
                particle.vx += dx * force * 0.01;
                particle.vy += dy * force * 0.01;
            }
            
            // Apply friction
            particle.vx *= 0.99;
            particle.vy *= 0.99;
        });
    }

    animate() {
        this.updateParticles();
        this.drawParticles();
        requestAnimationFrame(() => this.animate());
    }

    setupEventListeners() {
        window.addEventListener('resize', () => {
            this.resizeCanvas();
            this.createParticles();
        });

        window.addEventListener('mousemove', (e) => {
            this.mouse.x = e.clientX;
            this.mouse.y = e.clientY;
        });

        // Touch support for mobile
        window.addEventListener('touchmove', (e) => {
            this.mouse.x = e.touches[0].clientX;
            this.mouse.y = e.touches[0].clientY;
        });
    }
}

// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    new QuantumParticleField();
});

// Additional utility functions
function debounce(func, wait) {
    let timeout;
    return function executedFunction(...args) {
        const later = () => {
            clearTimeout(timeout);
            func(...args);
        };
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
    };
}