TwoQuarks commited on
Commit
ec09bf0
·
verified ·
1 Parent(s): 8cdecb1

Update quantum-field.js

Browse files
Files changed (1) hide show
  1. quantum-field.js +208 -208
quantum-field.js CHANGED
@@ -1,209 +1,209 @@
1
- /**
2
- * TwoQuarks Quantum Field - Ultra Blue Particle System
3
- * High-performance canvas animation with WebGL-style particles
4
- */
5
-
6
- class QuantumField {
7
- constructor(canvasId) {
8
- this.canvas = document.getElementById(canvasId);
9
- if (!this.canvas) {
10
- console.warn(`Canvas ${canvasId} not found`);
11
- return;
12
- }
13
-
14
- this.ctx = this.canvas.getContext('2d', { alpha: false });
15
- this.particles = [];
16
- this.connections = [];
17
- this.mouse = { x: null, y: null, radius: 150 };
18
-
19
- // Ultra Blue color palette
20
- this.colors = {
21
- primary: 'rgba(59, 130, 246, 0.8)', // #3B82F6
22
- bright: 'rgba(96, 165, 250, 0.6)', // #60A5FA
23
- deep: 'rgba(30, 64, 175, 0.9)', // #1E40AF
24
- glow: 'rgba(59, 130, 246, 0.15)',
25
- connection: 'rgba(59, 130, 246, 0.12)'
26
- };
27
-
28
- // Configuration
29
- this.config = {
30
- particleCount: 120,
31
- particleSpeed: 0.3,
32
- connectionDistance: 140,
33
- mouseInteraction: true,
34
- mouseRepelForce: 0.8,
35
- particleSize: { min: 1, max: 3 },
36
- glowEnabled: true
37
- };
38
-
39
- this.init();
40
- }
41
-
42
- init() {
43
- this.resize();
44
- this.createParticles();
45
- this.setupEventListeners();
46
- this.animate();
47
- }
48
-
49
- resize() {
50
- this.canvas.width = window.innerWidth;
51
- this.canvas.height = window.innerHeight;
52
- }
53
-
54
- createParticles() {
55
- this.particles = [];
56
- const { particleCount, particleSpeed, particleSize } = this.config;
57
-
58
- for (let i = 0; i < particleCount; i++) {
59
- this.particles.push({
60
- x: Math.random() * this.canvas.width,
61
- y: Math.random() * this.canvas.height,
62
- vx: (Math.random() - 0.5) * particleSpeed,
63
- vy: (Math.random() - 0.5) * particleSpeed,
64
- size: Math.random() * (particleSize.max - particleSize.min) + particleSize.min,
65
- color: this.getRandomColor(),
66
- brightness: Math.random() * 0.5 + 0.5
67
- });
68
- }
69
- }
70
-
71
- getRandomColor() {
72
- const colorOptions = [
73
- this.colors.primary,
74
- this.colors.bright,
75
- this.colors.deep
76
- ];
77
- return colorOptions[Math.floor(Math.random() * colorOptions.length)];
78
- }
79
-
80
- setupEventListeners() {
81
- window.addEventListener('resize', () => this.resize());
82
-
83
- if (this.config.mouseInteraction) {
84
- window.addEventListener('mousemove', (e) => {
85
- this.mouse.x = e.clientX;
86
- this.mouse.y = e.clientY;
87
- });
88
-
89
- window.addEventListener('mouseleave', () => {
90
- this.mouse.x = null;
91
- this.mouse.y = null;
92
- });
93
- }
94
- }
95
-
96
- updateParticles() {
97
- const { width, height } = this.canvas;
98
- const { mouseRepelForce } = this.config;
99
-
100
- this.particles.forEach(p => {
101
- // Mouse interaction - repel effect
102
- if (this.mouse.x !== null && this.mouse.y !== null) {
103
- const dx = p.x - this.mouse.x;
104
- const dy = p.y - this.mouse.y;
105
- const dist = Math.sqrt(dx * dx + dy * dy);
106
-
107
- if (dist < this.mouse.radius) {
108
- const force = (this.mouse.radius - dist) / this.mouse.radius;
109
- const angle = Math.atan2(dy, dx);
110
- p.vx += Math.cos(angle) * force * mouseRepelForce;
111
- p.vy += Math.sin(angle) * force * mouseRepelForce;
112
- }
113
- }
114
-
115
- // Update position
116
- p.x += p.vx;
117
- p.y += p.vy;
118
-
119
- // Damping
120
- p.vx *= 0.99;
121
- p.vy *= 0.99;
122
-
123
- // Boundary wrapping
124
- if (p.x < 0) p.x = width;
125
- if (p.x > width) p.x = 0;
126
- if (p.y < 0) p.y = height;
127
- if (p.y > height) p.y = 0;
128
-
129
- // Subtle brightness pulsing
130
- p.brightness += (Math.random() - 0.5) * 0.02;
131
- p.brightness = Math.max(0.3, Math.min(1, p.brightness));
132
- });
133
- }
134
-
135
- drawConnections() {
136
- const { connectionDistance } = this.config;
137
- this.ctx.strokeStyle = this.colors.connection;
138
- this.ctx.lineWidth = 0.5;
139
-
140
- for (let i = 0; i < this.particles.length; i++) {
141
- for (let j = i + 1; j < this.particles.length; j++) {
142
- const dx = this.particles[i].x - this.particles[j].x;
143
- const dy = this.particles[i].y - this.particles[j].y;
144
- const dist = Math.sqrt(dx * dx + dy * dy);
145
-
146
- if (dist < connectionDistance) {
147
- const opacity = (1 - dist / connectionDistance) * 0.3;
148
- this.ctx.strokeStyle = `rgba(59, 130, 246, ${opacity})`;
149
-
150
- this.ctx.beginPath();
151
- this.ctx.moveTo(this.particles[i].x, this.particles[i].y);
152
- this.ctx.lineTo(this.particles[j].x, this.particles[j].y);
153
- this.ctx.stroke();
154
- }
155
- }
156
- }
157
- }
158
-
159
- drawParticles() {
160
- this.particles.forEach(p => {
161
- // Glow effect
162
- if (this.config.glowEnabled) {
163
- const gradient = this.ctx.createRadialGradient(
164
- p.x, p.y, 0,
165
- p.x, p.y, p.size * 4
166
- );
167
- gradient.addColorStop(0, p.color.replace(/[\d.]+\)$/g, `${p.brightness})`));
168
- gradient.addColorStop(1, p.color.replace(/[\d.]+\)$/g, '0)'));
169
-
170
- this.ctx.fillStyle = gradient;
171
- this.ctx.beginPath();
172
- this.ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
173
- this.ctx.fill();
174
- }
175
-
176
- // Core particle
177
- this.ctx.fillStyle = p.color.replace(/[\d.]+\)$/g, `${p.brightness})`);
178
- this.ctx.beginPath();
179
- this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
180
- this.ctx.fill();
181
- });
182
- }
183
-
184
- animate() {
185
- // Clear with black background
186
- this.ctx.fillStyle = '#000000';
187
- this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
188
-
189
- this.updateParticles();
190
- this.drawConnections();
191
- this.drawParticles();
192
-
193
- requestAnimationFrame(() => this.animate());
194
- }
195
- }
196
-
197
- // Auto-initialize when DOM is ready
198
- if (document.readyState === 'loading') {
199
- document.addEventListener('DOMContentLoaded', () => {
200
- new QuantumField('quantumField');
201
- });
202
- } else {
203
- new QuantumField('quantumField');
204
- }
205
-
206
- // Export for potential external use
207
- if (typeof module !== 'undefined' && module.exports) {
208
- module.exports = QuantumField;
209
  }
 
1
+ /**
2
+ * TwoQuarks Quantum Field - Ultra Blue Particle System
3
+ * High-performance canvas animation with WebGL-style particles
4
+ */
5
+
6
+ class QuantumField {
7
+ constructor(canvasId) {
8
+ this.canvas = document.getElementById(canvasId);
9
+ if (!this.canvas) {
10
+ console.warn(`Canvas ${canvasId} not found`);
11
+ return;
12
+ }
13
+
14
+ this.ctx = this.canvas.getContext('2d', { alpha: false });
15
+ this.particles = [];
16
+ this.connections = [];
17
+ this.mouse = { x: null, y: null, radius: 150 };
18
+
19
+ // Ultra Blue color palette
20
+ this.colors = {
21
+ primary: 'rgba(39, 80, 146, 0.8)', // #3B82F6
22
+ bright: 'rgba(96, 165, 250, 0.6)', // #60A5FA
23
+ deep: 'rgba(30, 64, 175, 0.9)', // #1E40AF
24
+ glow: 'rgba(59, 130, 246, 0.15)',
25
+ connection: 'rgba(59, 130, 246, 0.12)'
26
+ };
27
+
28
+ // Configuration
29
+ this.config = {
30
+ particleCount: 120,
31
+ particleSpeed: 0.3,
32
+ connectionDistance: 140,
33
+ mouseInteraction: true,
34
+ mouseRepelForce: 0.8,
35
+ particleSize: { min: 1, max: 3 },
36
+ glowEnabled: true
37
+ };
38
+
39
+ this.init();
40
+ }
41
+
42
+ init() {
43
+ this.resize();
44
+ this.createParticles();
45
+ this.setupEventListeners();
46
+ this.animate();
47
+ }
48
+
49
+ resize() {
50
+ this.canvas.width = window.innerWidth;
51
+ this.canvas.height = window.innerHeight;
52
+ }
53
+
54
+ createParticles() {
55
+ this.particles = [];
56
+ const { particleCount, particleSpeed, particleSize } = this.config;
57
+
58
+ for (let i = 0; i < particleCount; i++) {
59
+ this.particles.push({
60
+ x: Math.random() * this.canvas.width,
61
+ y: Math.random() * this.canvas.height,
62
+ vx: (Math.random() - 0.5) * particleSpeed,
63
+ vy: (Math.random() - 0.5) * particleSpeed,
64
+ size: Math.random() * (particleSize.max - particleSize.min) + particleSize.min,
65
+ color: this.getRandomColor(),
66
+ brightness: Math.random() * 0.5 + 0.5
67
+ });
68
+ }
69
+ }
70
+
71
+ getRandomColor() {
72
+ const colorOptions = [
73
+ this.colors.primary,
74
+ this.colors.bright,
75
+ this.colors.deep
76
+ ];
77
+ return colorOptions[Math.floor(Math.random() * colorOptions.length)];
78
+ }
79
+
80
+ setupEventListeners() {
81
+ window.addEventListener('resize', () => this.resize());
82
+
83
+ if (this.config.mouseInteraction) {
84
+ window.addEventListener('mousemove', (e) => {
85
+ this.mouse.x = e.clientX;
86
+ this.mouse.y = e.clientY;
87
+ });
88
+
89
+ window.addEventListener('mouseleave', () => {
90
+ this.mouse.x = null;
91
+ this.mouse.y = null;
92
+ });
93
+ }
94
+ }
95
+
96
+ updateParticles() {
97
+ const { width, height } = this.canvas;
98
+ const { mouseRepelForce } = this.config;
99
+
100
+ this.particles.forEach(p => {
101
+ // Mouse interaction - repel effect
102
+ if (this.mouse.x !== null && this.mouse.y !== null) {
103
+ const dx = p.x - this.mouse.x;
104
+ const dy = p.y - this.mouse.y;
105
+ const dist = Math.sqrt(dx * dx + dy * dy);
106
+
107
+ if (dist < this.mouse.radius) {
108
+ const force = (this.mouse.radius - dist) / this.mouse.radius;
109
+ const angle = Math.atan2(dy, dx);
110
+ p.vx += Math.cos(angle) * force * mouseRepelForce;
111
+ p.vy += Math.sin(angle) * force * mouseRepelForce;
112
+ }
113
+ }
114
+
115
+ // Update position
116
+ p.x += p.vx;
117
+ p.y += p.vy;
118
+
119
+ // Damping
120
+ p.vx *= 0.99;
121
+ p.vy *= 0.99;
122
+
123
+ // Boundary wrapping
124
+ if (p.x < 0) p.x = width;
125
+ if (p.x > width) p.x = 0;
126
+ if (p.y < 0) p.y = height;
127
+ if (p.y > height) p.y = 0;
128
+
129
+ // Subtle brightness pulsing
130
+ p.brightness += (Math.random() - 0.5) * 0.02;
131
+ p.brightness = Math.max(0.3, Math.min(1, p.brightness));
132
+ });
133
+ }
134
+
135
+ drawConnections() {
136
+ const { connectionDistance } = this.config;
137
+ this.ctx.strokeStyle = this.colors.connection;
138
+ this.ctx.lineWidth = 0.5;
139
+
140
+ for (let i = 0; i < this.particles.length; i++) {
141
+ for (let j = i + 1; j < this.particles.length; j++) {
142
+ const dx = this.particles[i].x - this.particles[j].x;
143
+ const dy = this.particles[i].y - this.particles[j].y;
144
+ const dist = Math.sqrt(dx * dx + dy * dy);
145
+
146
+ if (dist < connectionDistance) {
147
+ const opacity = (1 - dist / connectionDistance) * 0.3;
148
+ this.ctx.strokeStyle = `rgba(29, 80, 126, ${opacity})`;
149
+
150
+ this.ctx.beginPath();
151
+ this.ctx.moveTo(this.particles[i].x, this.particles[i].y);
152
+ this.ctx.lineTo(this.particles[j].x, this.particles[j].y);
153
+ this.ctx.stroke();
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ drawParticles() {
160
+ this.particles.forEach(p => {
161
+ // Glow effect
162
+ if (this.config.glowEnabled) {
163
+ const gradient = this.ctx.createRadialGradient(
164
+ p.x, p.y, 0,
165
+ p.x, p.y, p.size * 4
166
+ );
167
+ gradient.addColorStop(0, p.color.replace(/[\d.]+\)$/g, `${p.brightness})`));
168
+ gradient.addColorStop(1, p.color.replace(/[\d.]+\)$/g, '0)'));
169
+
170
+ this.ctx.fillStyle = gradient;
171
+ this.ctx.beginPath();
172
+ this.ctx.arc(p.x, p.y, p.size * 4, 0, Math.PI * 2);
173
+ this.ctx.fill();
174
+ }
175
+
176
+ // Core particle
177
+ this.ctx.fillStyle = p.color.replace(/[\d.]+\)$/g, `${p.brightness})`);
178
+ this.ctx.beginPath();
179
+ this.ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
180
+ this.ctx.fill();
181
+ });
182
+ }
183
+
184
+ animate() {
185
+ // Clear with black background
186
+ this.ctx.fillStyle = '#000000';
187
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
188
+
189
+ this.updateParticles();
190
+ this.drawConnections();
191
+ this.drawParticles();
192
+
193
+ requestAnimationFrame(() => this.animate());
194
+ }
195
+ }
196
+
197
+ // Auto-initialize when DOM is ready
198
+ if (document.readyState === 'loading') {
199
+ document.addEventListener('DOMContentLoaded', () => {
200
+ new QuantumField('quantumField');
201
+ });
202
+ } else {
203
+ new QuantumField('quantumField');
204
+ }
205
+
206
+ // Export for potential external use
207
+ if (typeof module !== 'undefined' && module.exports) {
208
+ module.exports = QuantumField;
209
  }