TheGreatUnknown commited on
Commit
18f712e
·
verified ·
1 Parent(s): 566d814

Update scripts.js

Browse files
Files changed (1) hide show
  1. scripts.js +182 -980
scripts.js CHANGED
@@ -1,987 +1,189 @@
1
  document.addEventListener('DOMContentLoaded', function() {
2
- // Canvas setup
3
- const canvas = document.getElementById('canvas');
4
- const ctx = canvas.getContext('2d');
5
-
6
- // Set canvas size to window size
7
- canvas.width = window.innerWidth;
8
- canvas.height = window.innerHeight;
9
-
10
- // Center coordinates
11
- let centerX = canvas.width / 2;
12
- let centerY = canvas.height / 2;
13
-
14
- // Animation controls
15
- let animationRunning = true;
16
- let showParticles = true;
17
- let showConnections = true;
18
-
19
- // Brainwave and field controls
20
- let brainwaveState = "alpha"; // default
21
- let frequencyMultiplier = 1.0;
22
- let amplitudeMultiplier = 1.0;
23
- let coherenceMultiplier = 1.0;
24
-
25
- // Harmonic patterns
26
- let activeHarmonics = null; // none, fibonacci, goldenRatio, prime
27
-
28
- // AI response system
29
- let aiThoughts = [];
30
- let aiResponseLastUpdate = 0;
31
-
32
- // Configuration
33
- const config = {
34
- // Brain/consciousness parameters
35
- brainRadius: Math.min(canvas.width, canvas.height) * 0.05,
36
- brainColor: '#2271ff',
37
- brainPulseSpeed: 0.005,
38
- brainPulseRange: 0.3,
39
-
40
- // Field parameters
41
- fieldCount: 5,
42
- fieldLayers: 3,
43
- fieldWaveCount: 8,
44
- fieldMaxRadius: Math.min(canvas.width, canvas.height) * 0.4,
45
- fieldBaseOpacity: 0.15,
46
- fieldColors: ['#4e95ff', '#19d4ff', '#00c8ff', '#0096ff', '#0073ff'],
47
- fieldWaveSpeed: 0.6,
48
-
49
- // Particle parameters
50
- particleCount: 150,
51
- particleRadius: 2,
52
- particleBaseColor: '#ffffff',
53
- particleSpeed: 0.5,
54
- particleInfluenceThreshold: 100,
55
- particleInfluenceStrength: 0.015,
56
-
57
- // Connection parameters
58
- connectionOpacity: 0.15,
59
- connectionThreshold: 100,
60
- maxConnections: 3,
61
-
62
- // Brainwave parameters
63
- brainwaves: {
64
- delta: {
65
- pulseSpeed: 0.002,
66
- pulseRange: 0.5,
67
- waveSpeed: 0.3,
68
- particleInfluence: 0.01,
69
- color: '#3a5ad9',
70
- particleBehavior: 'slow',
71
- aiDescription: "Deep, unconscious processing. Particles move slowly in predictable patterns."
72
- },
73
- theta: {
74
- pulseSpeed: 0.004,
75
- pulseRange: 0.4,
76
- waveSpeed: 0.5,
77
- particleInfluence: 0.015,
78
- color: '#4f7ff5',
79
- particleBehavior: 'meditative',
80
- aiDescription: "Meditative state. Particles form flowing circular patterns."
81
- },
82
- alpha: {
83
- pulseSpeed: 0.006,
84
- pulseRange: 0.3,
85
- waveSpeed: 0.7,
86
- particleInfluence: 0.02,
87
- color: '#2271ff',
88
- particleBehavior: 'calm',
89
- aiDescription: "Relaxed, creative state. Balanced particle movement with emerging patterns."
90
- },
91
- beta: {
92
- pulseSpeed: 0.01,
93
- pulseRange: 0.2,
94
- waveSpeed: 1.0,
95
- particleInfluence: 0.03,
96
- color: '#008aff',
97
- particleBehavior: 'active',
98
- aiDescription: "Active thinking state. Particles move rapidly with clear structured connections."
99
- },
100
- gamma: {
101
- pulseSpeed: 0.015,
102
- pulseRange: 0.15,
103
- waveSpeed: 1.5,
104
- particleInfluence: 0.04,
105
- color: '#00c8ff',
106
- particleBehavior: 'hyperactive',
107
- aiDescription: "Higher consciousness state. Rapid particle movement forms complex geometric patterns."
108
- }
109
- },
110
-
111
  // Harmonic patterns
112
- harmonics: {
113
- fibonacci: {
114
- sequence: [1, 1, 2, 3, 5, 8, 13, 21],
115
- description: "Particles organizing into spiral patterns",
116
- color: '#ffd700'
117
- },
118
- goldenRatio: {
119
- ratio: 1.618,
120
- description: "Particles forming balanced, proportional structures",
121
- color: '#ff9d00'
122
- },
123
- prime: {
124
- sequence: [2, 3, 5, 7, 11, 13, 17, 19],
125
- description: "Particles arranging in prime-based geometrical structures",
126
- color: '#ff5e00'
127
- }
128
- }
129
- };
130
-
131
- // Objects for the animation
132
- let brain = {
133
- pulsePhase: 0
134
- };
135
-
136
- let fields = [];
137
- let particles = [];
138
-
139
- // Initialize electromagnetic fields
140
- for (let i = 0; i < config.fieldCount; i++) {
141
- const field = {
142
- id: i,
143
- color: config.fieldColors[i % config.fieldColors.length],
144
- waves: [],
145
- angle: (Math.PI * 2 / config.fieldCount) * i,
146
- phase: Math.random() * Math.PI * 2
147
- };
148
-
149
- // Create waves for each field
150
- for (let j = 0; j < config.fieldWaveCount; j++) {
151
- field.waves.push({
152
- progress: j / config.fieldWaveCount,
153
- speed: config.fieldWaveSpeed * (0.8 + Math.random() * 0.4),
154
- amplitude: 0.5 + Math.random() * 0.5
155
- });
156
- }
157
-
158
- fields.push(field);
159
- }
160
-
161
- // Initialize reality particles
162
- for (let i = 0; i < config.particleCount; i++) {
163
- particles.push({
164
- x: Math.random() * canvas.width,
165
- y: Math.random() * canvas.height,
166
- radius: config.particleRadius * (0.5 + Math.random()),
167
- baseSpeed: config.particleSpeed * (0.5 + Math.random()),
168
- angle: Math.random() * Math.PI * 2,
169
- color: config.particleBaseColor,
170
- influenced: false,
171
- influenceFactor: 0,
172
- // New properties for enhanced behavior
173
- age: 0,
174
- evolution: 0,
175
- harmonicFactor: 0,
176
- structureRole: null
177
- });
178
- }
179
-
180
- // Connect UI controls
181
- function setupControls() {
182
- // Brainwave buttons
183
- document.getElementById('deltaBrain').addEventListener('click', () => setBrainwaveState('delta'));
184
- document.getElementById('thetaBrain').addEventListener('click', () => setBrainwaveState('theta'));
185
- document.getElementById('alphaBrain').addEventListener('click', () => setBrainwaveState('alpha'));
186
- document.getElementById('betaBrain').addEventListener('click', () => setBrainwaveState('beta'));
187
- document.getElementById('gammaBrain').addEventListener('click', () => setBrainwaveState('gamma'));
188
-
189
- // Sliders
190
- document.getElementById('frequencySlider').addEventListener('input', function() {
191
- frequencyMultiplier = parseFloat(this.value);
192
- document.getElementById('frequencyValue').textContent = frequencyMultiplier.toFixed(1);
193
- updateAIResponse();
194
- });
195
-
196
- document.getElementById('amplitudeSlider').addEventListener('input', function() {
197
- amplitudeMultiplier = parseFloat(this.value);
198
- document.getElementById('amplitudeValue').textContent = amplitudeMultiplier.toFixed(1);
199
- updateAIResponse();
200
- });
201
-
202
- document.getElementById('coherenceSlider').addEventListener('input', function() {
203
- coherenceMultiplier = parseFloat(this.value);
204
- document.getElementById('coherenceValue').textContent = coherenceMultiplier.toFixed(1);
205
- updateAIResponse();
206
- });
207
-
208
- // Harmonic buttons
209
- document.getElementById('fibonacciButton').addEventListener('click', function() {
210
- toggleHarmonic('fibonacci');
211
- });
212
-
213
- document.getElementById('goldenRatioButton').addEventListener('click', function() {
214
- toggleHarmonic('goldenRatio');
215
- });
216
-
217
- document.getElementById('primeButton').addEventListener('click', function() {
218
- toggleHarmonic('prime');
219
- });
220
- }
221
-
222
- // Function to set brainwave state
223
- function setBrainwaveState(state) {
224
- brainwaveState = state;
225
-
226
- // Update brain parameters based on brainwave state
227
- const brainwaveConfig = config.brainwaves[state];
228
- config.brainPulseSpeed = brainwaveConfig.pulseSpeed;
229
- config.brainPulseRange = brainwaveConfig.pulseRange;
230
- config.fieldWaveSpeed = brainwaveConfig.waveSpeed;
231
- config.particleInfluenceStrength = brainwaveConfig.particleInfluence;
232
- config.brainColor = brainwaveConfig.color;
233
-
234
- // Reset all brainwave buttons to default style
235
- document.querySelectorAll('.brainwave-buttons button').forEach(btn => {
236
- btn.style.backgroundColor = '#2a2a2a';
237
- btn.style.color = 'white';
238
- });
239
-
240
- // Highlight the active button
241
- const activeBtn = document.getElementById(state + 'Brain');
242
- if (activeBtn) {
243
- activeBtn.style.backgroundColor = brainwaveConfig.color;
244
- activeBtn.style.color = 'black';
245
- }
246
-
247
- updateAIResponse();
248
- }
249
-
250
- // Function to toggle harmonic patterns
251
- function toggleHarmonic(harmonic) {
252
- if (activeHarmonics === harmonic) {
253
- // Turn off if already active
254
- activeHarmonics = null;
255
- document.querySelectorAll('.harmonics-section button').forEach(btn => {
256
- btn.style.backgroundColor = '#2a2a2a';
257
- btn.style.color = 'white';
258
- });
259
- } else {
260
- // Set new harmonic
261
- activeHarmonics = harmonic;
262
-
263
- // Reset all harmonic buttons
264
- document.querySelectorAll('.harmonics-section button').forEach(btn => {
265
- btn.style.backgroundColor = '#2a2a2a';
266
- btn.style.color = 'white';
267
- });
268
-
269
- // Highlight active button
270
- const harmonicConfig = config.harmonics[harmonic];
271
- const btnId = harmonic + 'Button';
272
- const btn = document.getElementById(btnId);
273
- if (btn) {
274
- btn.style.backgroundColor = harmonicConfig.color;
275
- btn.style.color = 'black';
276
- }
277
- }
278
-
279
- updateAIResponse();
280
- }
281
-
282
- // Event listeners for buttons
283
- document.getElementById('togglePlay').addEventListener('click', function() {
284
- animationRunning = !animationRunning;
285
- this.textContent = animationRunning ? 'Pause' : 'Play';
286
- if (animationRunning) animate();
287
- });
288
-
289
- document.getElementById('toggleParticles').addEventListener('click', function() {
290
- showParticles = !showParticles;
291
- });
292
-
293
- document.getElementById('toggleConnections').addEventListener('click', function() {
294
- showConnections = !showConnections;
295
- });
296
-
297
- // Handle window resize
298
- window.addEventListener('resize', function() {
299
- canvas.width = window.innerWidth;
300
- canvas.height = window.innerHeight;
301
- config.brainRadius = Math.min(canvas.width, canvas.height) * 0.05;
302
- config.fieldMaxRadius = Math.min(canvas.width, canvas.height) * 0.4;
303
- centerX = canvas.width / 2;
304
- centerY = canvas.height / 2;
305
- });
306
-
307
- // Draw the brain/consciousness center
308
- function drawBrain() {
309
- const brainwaveConfig = config.brainwaves[brainwaveState];
310
- const adjustedPulseSpeed = config.brainPulseSpeed * frequencyMultiplier;
311
- const adjustedPulseRange = config.brainPulseRange * amplitudeMultiplier;
312
-
313
- brain.pulsePhase += adjustedPulseSpeed;
314
- const pulseFactor = 1 + Math.sin(brain.pulsePhase) * adjustedPulseRange;
315
-
316
- // Create gradient for brain
317
- const gradient = ctx.createRadialGradient(
318
- centerX, centerY, 0,
319
- centerX, centerY, config.brainRadius * pulseFactor
320
- );
321
- gradient.addColorStop(0, 'rgba(255, 255, 255, 1)');
322
- gradient.addColorStop(0.7, config.brainColor);
323
- gradient.addColorStop(1, 'rgba(34, 113, 255, 0)');
324
-
325
- // Draw brain sphere
326
- ctx.beginPath();
327
- ctx.arc(centerX, centerY, config.brainRadius * pulseFactor, 0, Math.PI * 2);
328
- ctx.fillStyle = gradient;
329
- ctx.fill();
330
-
331
- // Add some inner detail
332
- ctx.beginPath();
333
- ctx.arc(centerX, centerY, config.brainRadius * 0.6 * pulseFactor, 0, Math.PI * 2);
334
- ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
335
- ctx.fill();
336
-
337
- // Add harmonic patterns if active
338
- if (activeHarmonics) {
339
- drawHarmonicPatterns(pulseFactor);
340
- }
341
- }
342
-
343
- // Draw harmonic patterns inside the brain
344
- function drawHarmonicPatterns(pulseFactor) {
345
- const harmonicConfig = config.harmonics[activeHarmonics];
346
- ctx.strokeStyle = harmonicConfig.color;
347
- ctx.lineWidth = 1;
348
-
349
- if (activeHarmonics === 'fibonacci') {
350
- // Draw fibonacci spiral
351
- const a = config.brainRadius * 0.1;
352
- let fib1 = 1;
353
- let fib2 = 1;
354
-
355
- ctx.beginPath();
356
- for (let i = 0; i < 7; i++) {
357
- const nextFib = fib1 + fib2;
358
- const radius = a * fib2 / 5 * pulseFactor;
359
- ctx.arc(centerX, centerY, radius, 0, Math.PI / 2);
360
- ctx.translate(radius, 0);
361
- ctx.rotate(Math.PI / 2);
362
- fib1 = fib2;
363
- fib2 = nextFib;
364
- }
365
- ctx.stroke();
366
- }
367
- else if (activeHarmonics === 'goldenRatio') {
368
- // Draw golden ratio spirals
369
- const maxRadius = config.brainRadius * pulseFactor;
370
- const b = 0.4; // growth factor
371
-
372
- ctx.beginPath();
373
- for (let theta = 0; theta < 8 * Math.PI; theta += 0.1) {
374
- const r = maxRadius * Math.pow(Math.E, b * theta) / (8 * Math.PI);
375
- const x = centerX + r * Math.cos(theta);
376
- const y = centerY + r * Math.sin(theta);
377
-
378
- if (theta === 0) {
379
- ctx.moveTo(x, y);
380
- } else {
381
- ctx.lineTo(x, y);
382
- }
383
- }
384
- ctx.stroke();
385
- }
386
- else if (activeHarmonics === 'prime') {
387
- // Draw prime-based pattern
388
- const primes = config.harmonics.prime.sequence;
389
- const maxRadius = config.brainRadius * pulseFactor;
390
-
391
- ctx.beginPath();
392
- for (let i = 0; i < primes.length; i++) {
393
- const radius = maxRadius * (primes[i] / primes[primes.length - 1]) * 0.8;
394
- const segments = primes[i];
395
-
396
- for (let j = 0; j < segments; j++) {
397
- const angle = (j / segments) * Math.PI * 2;
398
- const x = centerX + radius * Math.cos(angle);
399
- const y = centerY + radius * Math.sin(angle);
400
-
401
- if (j === 0) {
402
- ctx.moveTo(x, y);
403
- } else {
404
- ctx.lineTo(x, y);
405
- }
406
  }
407
- ctx.closePath();
408
- }
409
- ctx.stroke();
410
- }
411
- }
412
-
413
- // Draw electromagnetic fields
414
- function drawFields() {
415
- const adjustedWaveSpeed = config.fieldWaveSpeed * frequencyMultiplier;
416
-
417
- for (let i = 0; i < fields.length; i++) {
418
- const field = fields[i];
419
-
420
- // Update field phase
421
- field.phase += 0.01 * frequencyMultiplier;
422
-
423
- // Apply coherence multiplier
424
- const waveCoherence = coherenceMultiplier;
425
- const phaseShift = field.id * (Math.PI * 2 / config.fieldCount) * waveCoherence;
426
-
427
- // Draw each wave of the field
428
- for (let j = 0; j < field.waves.length; j++) {
429
- const wave = field.waves[j];
430
-
431
- // Update wave progress
432
- let waveSpeed = adjustedWaveSpeed * 0.001 * wave.speed;
433
-
434
- // Apply harmonic patterns if active
435
- if (activeHarmonics === 'fibonacci') {
436
- const fibIndex = j % config.harmonics.fibonacci.sequence.length;
437
- waveSpeed *= config.harmonics.fibonacci.sequence[fibIndex] / 8;
438
- }
439
- else if (activeHarmonics === 'goldenRatio') {
440
- waveSpeed *= Math.pow(config.harmonics.goldenRatio.ratio, j % 5) / 5;
441
- }
442
- else if (activeHarmonics === 'prime') {
443
- const primeIndex = j % config.harmonics.prime.sequence.length;
444
- waveSpeed *= config.harmonics.prime.sequence[primeIndex] / 10;
445
- }
446
-
447
- wave.progress += waveSpeed;
448
- if (wave.progress > 1) wave.progress = 0;
449
-
450
- // Calculate wave radius
451
- const radius = config.brainRadius + wave.progress * (config.fieldMaxRadius - config.brainRadius);
452
-
453
- // Calculate wave opacity based on progress
454
- let opacity = config.fieldBaseOpacity * (1 - wave.progress) * amplitudeMultiplier;
455
-
456
- // Harmonic patterns affect opacity
457
- if (activeHarmonics) {
458
- opacity *= (1 + 0.5 * Math.sin(wave.progress * Math.PI * 10));
459
- }
460
-
461
- // Wave color
462
- let waveColor = field.color;
463
- if (activeHarmonics) {
464
- waveColor = config.harmonics[activeHarmonics].color;
465
- }
466
-
467
- // Draw the wave
468
- ctx.beginPath();
469
-
470
- // Standard circular waves for most states
471
- if (!activeHarmonics || brainwaveState !== 'gamma') {
472
- ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
473
- }
474
- // Complex wave patterns for gamma + harmonics
475
- else {
476
- const points = 50;
477
- for (let p = 0; p <= points; p++) {
478
- const angle = (p / points) * Math.PI * 2;
479
-
480
- // Calculate modulation based on harmonic pattern
481
- let modulation = 1;
482
- if (activeHarmonics === 'fibonacci') {
483
- modulation = 1 + 0.2 * Math.sin(angle * config.harmonics.fibonacci.sequence[j % config.harmonics.fibonacci.sequence.length]);
484
- } else if (activeHarmonics === 'goldenRatio') {
485
- modulation = 1 + 0.3 * Math.sin(angle * config.harmonics.goldenRatio.ratio);
486
- } else if (activeHarmonics === 'prime') {
487
- modulation = 1 + 0.25 * Math.sin(angle * config.harmonics.prime.sequence[j % config.harmonics.prime.sequence.length]);
488
- }
489
-
490
- const r = radius * modulation;
491
- const x = centerX + r * Math.cos(angle + field.phase);
492
- const y = centerY + r * Math.sin(angle + field.phase);
493
-
494
- if (p === 0) {
495
- ctx.moveTo(x, y);
496
- } else {
497
- ctx.lineTo(x, y);
498
- }
499
- }
500
- ctx.closePath();
501
- }
502
-
503
- ctx.strokeStyle = `rgba(${hexToRgb(waveColor)}, ${opacity})`;
504
- ctx.lineWidth = 1 + (1 - wave.progress) * 2 * amplitudeMultiplier;
505
- ctx.stroke();
506
- }
507
- }
508
- }
509
-
510
- // Draw reality particles
511
- function drawParticles() {
512
- if (!showParticles) return;
513
-
514
- // Group all influenced particles by their evolution level
515
- const particlesByEvolution = {};
516
- const influencedParticles = particles.filter(p => p.influenced);
517
-
518
- for (let i = 0; i < influencedParticles.length; i++) {
519
- const evo = Math.floor(influencedParticles[i].evolution * 5);
520
- if (!particlesByEvolution[evo]) {
521
- particlesByEvolution[evo] = [];
522
- }
523
- particlesByEvolution[evo].push(influencedParticles[i]);
524
- }
525
-
526
- // Draw connections between influenced particles
527
- if (showConnections) {
528
- for (let i = 0; i < particles.length; i++) {
529
- const p1 = particles[i];
530
- if (!p1.influenced) continue;
531
-
532
- let connections = 0;
533
- for (let j = i + 1; j < particles.length; j++) {
534
- if (connections >= config.maxConnections) break;
535
-
536
- const p2 = particles[j];
537
- if (!p2.influenced) continue;
538
-
539
- const dx = p1.x - p2.x;
540
- const dy = p1.y - p2.y;
541
- const distance = Math.sqrt(dx * dx + dy * dy);
542
-
543
- // Connection threshold is affected by field coherence
544
- const adjustedThreshold = config.connectionThreshold * coherenceMultiplier;
545
-
546
- if (distance < adjustedThreshold) {
547
- let opacity = config.connectionOpacity * (1 - distance / adjustedThreshold);
548
-
549
- // Harmonic patterns enhance connections
550
- if (activeHarmonics) {
551
- opacity *= 1.5;
552
- // Add a wave effect to connection
553
- const phase = Date.now() * 0.001 * frequencyMultiplier;
554
- opacity *= (0.7 + 0.3 * Math.sin(phase * 5 + distance * 0.05));
555
- }
556
-
557
- // Brainwave state affects connection color
558
- let connectionColor = 'rgba(255, 255, 255, ' + opacity + ')';
559
- if (brainwaveState === 'gamma' && p1.evolution > 0.5 && p2.evolution > 0.5) {
560
- connectionColor = `rgba(${hexToRgb(config.brainColor)}, ${opacity * 1.2})`;
561
- }
562
-
563
- ctx.beginPath();
564
- ctx.moveTo(p1.x, p1.y);
565
- ctx.lineTo(p2.x, p2.y);
566
- ctx.strokeStyle = connectionColor;
567
- ctx.lineWidth = 0.5 * (p1.evolution + p2.evolution + 1);
568
- ctx.stroke();
569
- connections++;
570
- }
571
- }
572
- }
573
-
574
- // Draw structure connections for higher evolution particles
575
- if (activeHarmonics && (brainwaveState === 'theta' || brainwaveState === 'alpha' || brainwaveState === 'gamma')) {
576
- const highEvoParticles = particles.filter(p => p.influenced && p.evolution > 0.6);
577
-
578
- if (highEvoParticles.length > 3) {
579
- ctx.beginPath();
580
-
581
- if (activeHarmonics === 'fibonacci') {
582
- // Draw fibonacci-based structure
583
- for (let i = 0; i < Math.min(8, highEvoParticles.length); i++) {
584
- const p = highEvoParticles[i];
585
- if (i === 0) {
586
- ctx.moveTo(p.x, p.y);
587
- } else {
588
- ctx.lineTo(p.x, p.y);
589
- }
590
- }
591
- }
592
- else if (activeHarmonics === 'goldenRatio') {
593
- // Draw pentagon-like structure
594
- const centerPoint = {
595
- x: highEvoParticles.reduce((sum, p) => sum + p.x, 0) / highEvoParticles.length,
596
- y: highEvoParticles.reduce((sum, p) => sum + p.y, 0) / highEvoParticles.length
597
- };
598
-
599
- highEvoParticles.sort((a, b) => {
600
- const angleA = Math.atan2(a.y - centerPoint.y, a.x - centerPoint.x);
601
- const angleB = Math.atan2(b.y - centerPoint.y, b.x - centerPoint.x);
602
- return angleA - angleB;
603
  });
604
-
605
- for (let i = 0; i < Math.min(highEvoParticles.length, 5); i++) {
606
- const p = highEvoParticles[i];
607
- if (i === 0) {
608
- ctx.moveTo(p.x, p.y);
609
- } else {
610
- ctx.lineTo(p.x, p.y);
611
- }
612
- }
613
- ctx.closePath();
614
- }
615
- else if (activeHarmonics === 'prime') {
616
- // Connect particles in prime-based pattern
617
- for (let i = 0; i < Math.min(highEvoParticles.length, config.harmonics.prime.sequence.length); i++) {
618
- const idx = config.harmonics.prime.sequence[i] % highEvoParticles.length;
619
- const p = highEvoParticles[idx];
620
- if (i === 0) {
621
- ctx.moveTo(p.x, p.y);
622
- } else {
623
- ctx.lineTo(p.x, p.y);
624
- }
625
- }
626
- }
627
-
628
- ctx.strokeStyle = `rgba(${hexToRgb(config.harmonics[activeHarmonics].color)}, 0.7)`;
629
- ctx.lineWidth = 1.5;
630
- ctx.stroke();
631
- }
632
- }
633
- }
634
-
635
- // Draw and update each particle
636
- for (let i = 0; i < particles.length; i++) {
637
- const particle = particles[i];
638
-
639
- // Calculate distance from the brain center
640
- const dx = particle.x - centerX;
641
- const dy = particle.y - centerY;
642
- const distance = Math.sqrt(dx * dx + dy * dy);
643
-
644
- // Determine if particle is influenced by consciousness field
645
- const adjustedFieldRadius = config.fieldMaxRadius * amplitudeMultiplier;
646
- particle.influenced = distance < adjustedFieldRadius;
647
-
648
- // Calculate influence factor (stronger closer to the brain)
649
- particle.influenceFactor = particle.influenced ?
650
- Math.max(0, 1 - distance / adjustedFieldRadius) : 0;
651
-
652
- // Update particle evolution
653
- if (animationRunning) {
654
- if (particle.influenced) {
655
- particle.age += 0.001 * frequencyMultiplier;
656
-
657
- // Particles evolve more quickly in higher frequency brainwaves
658
- let evolutionRate = 0.0001;
659
- if (brainwaveState === 'gamma') evolutionRate *= 3;
660
- else if (brainwaveState === 'beta') evolutionRate *= 2;
661
-
662
- // Harmonics enhance evolution
663
- if (activeHarmonics) evolutionRate *= 2;
664
-
665
- particle.evolution = Math.min(1, particle.evolution + evolutionRate * particle.influenceFactor);
666
- } else {
667
- // Particles de-evolve when outside field
668
- particle.evolution = Math.max(0, particle.evolution - 0.0001);
669
- }
670
- }
671
-
672
- // Update particle position
673
- if (animationRunning) {
674
- // Base movement
675
- let speed = particle.baseSpeed;
676
-
677
- // Add field influence
678
- if (particle.influenced) {
679
- // Influenced particles move in spirals around the brain
680
- const angleToCenter = Math.atan2(dy, dx);
681
- // Perpendicular direction for circular motion
682
- const perpendicularAngle = angleToCenter + Math.PI / 2;
683
-
684
- // Apply brainwave state modifiers
685
- let influenceFactor = particle.influenceFactor;
686
-
687
- // Delta waves make movement more predictable/consistent
688
- if (brainwaveState === 'delta') {
689
- influenceFactor *= 1.5;
690
- perpendicularAngle += Math.sin(Date.now() * 0.001) * 0.2;
691
- }
692
- // Theta waves make movement more spiral-like
693
- else if (brainwaveState === 'theta') {
694
- perpendicularAngle += Math.sin(Date.now() * 0.0015) * 0.5;
695
- }
696
- // Beta waves make movement more direct and focused
697
- else if (brainwaveState === 'beta') {
698
- // More direct influence toward brain
699
- perpendicularAngle = perpendicularAngle * 0.7 + (angleToCenter + Math.PI) * 0.3;
700
- }
701
- // Gamma waves make movement complex and structured
702
- else if (brainwaveState === 'gamma') {
703
- // More complex movement patterns
704
- perpendicularAngle += Math.sin(Date.now() * 0.003 * particle.evolution) * 1.5;
705
- }
706
-
707
- // Apply harmonic patterns
708
- if (activeHarmonics === 'fibonacci') {
709
- // Fibonacci pattern: creates spiral-like orbits
710
- const fibIndex = Math.floor(particle.evolution * 7);
711
- const fib = config.harmonics.fibonacci.sequence[fibIndex % config.harmonics.fibonacci.sequence.length];
712
- perpendicularAngle += Math.sin(Date.now() * 0.001 * fib) * 0.3;
713
- }
714
- else if (activeHarmonics === 'goldenRatio') {
715
- // Golden ratio pattern: creates balanced, structured movement
716
- perpendicularAngle += Math.sin(Date.now() * 0.001 * config.harmonics.goldenRatio.ratio) * 0.5;
717
- speed *= (1 + 0.2 * Math.sin(particle.age * config.harmonics.goldenRatio.ratio));
718
- }
719
- else if (activeHarmonics === 'prime') {
720
- // Prime pattern: creates more chaotic but structured movement
721
- const primeIndex = Math.floor(particle.evolution * 7);
722
- const prime = config.harmonics.prime.sequence[primeIndex % config.harmonics.prime.sequence.length];
723
- perpendicularAngle += Math.cos(Date.now() * 0.0005 * prime) * 0.7;
724
- }
725
-
726
- // Final angle calculation
727
- particle.angle = (1 - particle.influenceFactor) * particle.angle + particle.influenceFactor * perpendicularAngle;
728
-
729
- // Speed increases with influence, modified by frequency and coherence
730
- const adjustedInfluenceStrength = config.particleInfluenceStrength *
731
- frequencyMultiplier *
732
- (0.5 + coherenceMultiplier * 0.5);
733
-
734
- speed += adjustedInfluenceStrength * particle.influenceFactor * distance;
735
-
736
- // Highly evolved particles in gamma brainwave can form structure
737
- if (brainwaveState === 'gamma' && particle.evolution > 0.8 && activeHarmonics) {
738
- // Structure formation behavior
739
- const structureAngle = Date.now() * 0.0005;
740
- const structureX = centerX + Math.cos(structureAngle + (i / particles.length) * Math.PI * 2) * adjustedFieldRadius * 0.5;
741
- const structureY = centerY + Math.sin(structureAngle + (i / particles.length) * Math.PI * 2) * adjustedFieldRadius * 0.5;
742
-
743
- // Move toward structure position
744
- const toStructureX = structureX - particle.x;
745
- const toStructureY = structureY - particle.y;
746
- const structureDistance = Math.sqrt(toStructureX * toStructureX + toStructureY * toStructureY);
747
- const structureAngleToMove = Math.atan2(toStructureY, toStructureX);
748
-
749
- // Blend between normal movement and structure formation
750
- particle.angle = particle.angle * 0.7 + structureAngleToMove * 0.3;
751
- speed = speed * 0.7 + (structureDistance * 0.01) * 0.3;
752
- }
753
- }
754
-
755
- particle.x += Math.cos(particle.angle) * speed;
756
- particle.y += Math.sin(particle.angle) * speed;
757
-
758
- // Wrap around edges
759
- if (particle.x < 0) particle.x = canvas.width;
760
- if (particle.x > canvas.width) particle.x = 0;
761
- if (particle.y < 0) particle.y = canvas.height;
762
- if (particle.y > canvas.height) particle.y = 0;
763
- }
764
-
765
- // Determine particle color based on influence, brainwave state, and evolution
766
- let color = config.particleBaseColor;
767
-
768
- if (particle.influenced) {
769
- // Base influence color
770
- color = lerpColor(config.particleBaseColor, config.brainColor, particle.influenceFactor);
771
-
772
- // Evolution affects color
773
- if (particle.evolution > 0.3) {
774
- // More evolved particles take on more of the brain's color
775
- color = lerpColor(color, config.brainColor, particle.evolution * 0.7);
776
-
777
- // Highly evolved particles in harmonic fields get special colors
778
- if (particle.evolution > 0.7 && activeHarmonics) {
779
- color = lerpColor(color, config.harmonics[activeHarmonics].color, (particle.evolution - 0.7) * 3);
780
- }
781
- }
782
- }
783
-
784
- // Determine particle size based on evolution
785
- let particleSize = particle.radius;
786
- if (particle.evolution > 0.5) {
787
- particleSize *= (1 + particle.evolution * 0.5);
788
- }
789
-
790
- // Draw the particle
791
- ctx.beginPath();
792
-
793
- // Shape changes based on evolution and brainwave state
794
- if (particle.evolution < 0.3 || brainwaveState === 'delta') {
795
- // Basic circle
796
- ctx.arc(particle.x, particle.y, particleSize, 0, Math.PI * 2);
797
- }
798
- else if (particle.evolution < 0.7 || brainwaveState === 'alpha') {
799
- // Slightly more complex shape
800
- if (brainwaveState === 'theta') {
801
- // Soft pulsing circle for theta
802
- const pulseSize = particleSize * (1 + 0.2 * Math.sin(Date.now() * 0.003));
803
- ctx.arc(particle.x, particle.y, pulseSize, 0, Math.PI * 2);
804
- } else {
805
- // Standard circle with glow for others
806
- ctx.arc(particle.x, particle.y, particleSize, 0, Math.PI * 2);
807
- }
808
- }
809
- else {
810
- // Advanced particles get more complex shapes in beta/gamma
811
- if (brainwaveState === 'beta') {
812
- // Diamond shape for beta
813
- ctx.moveTo(particle.x, particle.y - particleSize);
814
- ctx.lineTo(particle.x + particleSize, particle.y);
815
- ctx.lineTo(particle.x, particle.y + particleSize);
816
- ctx.lineTo(particle.x - particleSize, particle.y);
817
- ctx.closePath();
818
- }
819
- else if (brainwaveState === 'gamma') {
820
- // Star shape for gamma
821
- const outerRadius = particleSize * 1.2;
822
- const innerRadius = particleSize * 0.6;
823
-
824
- for (let j = 0; j < 5; j++) {
825
- const outerAngle = (j * Math.PI * 2 / 5) - Math.PI / 2;
826
- const innerAngle = ((j + 0.5) * Math.PI * 2 / 5) - Math.PI / 2;
827
-
828
- const outerX = particle.x + Math.cos(outerAngle) * outerRadius;
829
- const outerY = particle.y + Math.sin(outerAngle) * outerRadius;
830
- const innerX = particle.x + Math.cos(innerAngle) * innerRadius;
831
- const innerY = particle.y + Math.sin(innerAngle) * innerRadius;
832
-
833
- if (j === 0) {
834
- ctx.moveTo(outerX, outerY);
835
- } else {
836
- ctx.lineTo(outerX, outerY);
837
- }
838
- ctx.lineTo(innerX, innerY);
839
- }
840
- ctx.closePath();
841
- }
842
- else {
843
- // Default for other states
844
- ctx.arc(particle.x, particle.y, particleSize, 0, Math.PI * 2);
845
- }
846
- }
847
-
848
- ctx.fillStyle = color;
849
- ctx.fill();
850
-
851
- // Add glow for evolved particles
852
- if (particle.evolution > 0.5) {
853
- const glowSize = particleSize * (1 + particle.evolution);
854
- const gradient = ctx.createRadialGradient(
855
- particle.x, particle.y, particleSize * 0.5,
856
- particle.x, particle.y, glowSize
857
- );
858
- gradient.addColorStop(0, 'rgba(255, 255, 255, 0)');
859
- gradient.addColorStop(1, `rgba(${hexToRgb(color)}, 0)`);
860
-
861
  ctx.beginPath();
862
- ctx.arc(particle.x, particle.y, glowSize, 0, Math.PI * 2);
863
- ctx.fillStyle = gradient;
864
  ctx.fill();
865
- }
866
- }
867
- }
868
-
869
- // Helper function to interpolate between two colors
870
- function lerpColor(color1, color2, factor) {
871
- const rgb1 = hexToRgb(color1, true);
872
- const rgb2 = hexToRgb(color2, true);
873
-
874
- const r = Math.round(rgb1.r + factor * (rgb2.r - rgb1.r));
875
- const g = Math.round(rgb1.g + factor * (rgb2.g - rgb1.g));
876
- const b = Math.round(rgb1.b + factor * (rgb2.b - rgb1.b));
877
-
878
- return `rgb(${r}, ${g}, ${b})`;
879
- }
880
-
881
- // Helper function to convert hex to rgb
882
- function hexToRgb(hex, asObject = false) {
883
- // Remove # if present
884
- hex = hex.replace(/^#/, '');
885
-
886
- // Parse hex value
887
- const bigint = parseInt(hex, 16);
888
- const r = (bigint >> 16) & 255;
889
- const g = (bigint >> 8) & 255;
890
- const b = bigint & 255;
891
-
892
- return asObject ? { r, g, b } : `${r}, ${g}, ${b}`;
893
- }
894
-
895
- // AI response system
896
- function updateAIResponse() {
897
- const now = Date.now();
898
- if (now - aiResponseLastUpdate < 2000) return; // Limit update frequency
899
-
900
- aiResponseLastUpdate = now;
901
-
902
- // Analyze current state
903
- const brainwaveConfig = config.brainwaves[brainwaveState];
904
- const highlyEvolvedCount = particles.filter(p => p.influenced && p.evolution > 0.7).length;
905
- const totalInfluenced = particles.filter(p => p.influenced).length;
906
- const evolutionRatio = totalInfluenced > 0 ? highlyEvolvedCount / totalInfluenced : 0;
907
-
908
- // Generate thought based on current state
909
- let thought = brainwaveConfig.aiDescription;
910
-
911
- // Add insights based on controls
912
- if (frequencyMultiplier > 1.5) {
913
- thought += " High frequency waves accelerate particle evolution.";
914
- } else if (frequencyMultiplier < 0.5) {
915
- thought += " Low frequency waves create stable, predictable patterns.";
916
  }
917
-
918
- if (amplitudeMultiplier > 1.5) {
919
- thought += " Strong field amplitude extends consciousness reach.";
920
- }
921
-
922
- if (coherenceMultiplier > 1.5) {
923
- thought += " Field coherence enhances structured connections.";
924
- } else if (coherenceMultiplier < 0.5) {
925
- thought += " Low coherence creates chaotic but creative patterns.";
926
- }
927
-
928
- // Add harmonic insights
929
- if (activeHarmonics) {
930
- thought += " " + config.harmonics[activeHarmonics].description + ".";
931
-
932
- if (evolutionRatio > 0.3) {
933
- if (activeHarmonics === 'fibonacci') {
934
- thought += " Fibonacci resonance creating natural growth patterns.";
935
- } else if (activeHarmonics === 'goldenRatio') {
936
- thought += " Golden ratio harmonic generating balanced, aesthetic structures.";
937
- } else if (activeHarmonics === 'prime') {
938
- thought += " Prime number fields creating fundamental structural elements.";
939
- }
940
- }
941
- }
942
-
943
- // Add emergent behavior observations
944
- if (evolutionRatio > 0.5 && brainwaveState === 'gamma' && activeHarmonics) {
945
- const emergedThoughts = [
946
- "Consciousness field is structuring reality into ordered patterns.",
947
- "Self-organization emerging from harmonic resonance.",
948
- "Information structures crystallizing within consciousness field.",
949
- "Quantum coherence detected in particle behavior.",
950
- "Complex emergent intelligence forming in field interactions."
951
- ];
952
-
953
- thought += " " + emergedThoughts[Math.floor(Math.random() * emergedThoughts.length)];
954
- }
955
-
956
- // Store thought
957
- aiThoughts.push(thought);
958
- if (aiThoughts.length > 3) aiThoughts.shift();
959
-
960
- // Update UI
961
- document.getElementById('aiResponse').textContent = aiThoughts.join("\n\n");
962
- }
963
-
964
- // Main animation loop
965
- function animate() {
966
- if (!animationRunning) return;
967
-
968
- // Clear canvas
969
- ctx.clearRect(0, 0, canvas.width, canvas.height);
970
-
971
- // Draw all components
972
- drawFields();
973
- drawParticles();
974
- drawBrain();
975
-
976
- // Request next frame
977
- requestAnimationFrame(animate);
978
- }
979
-
980
- // Initialize
981
- setupControls();
982
- setBrainwaveState('alpha'); // Set initial state
983
- updateAIResponse();
984
-
985
- // Start animation
986
- animate();
987
- });
 
1
  document.addEventListener('DOMContentLoaded', function() {
2
+ console.log("WebSim Loaded! Initializing...");
3
+
4
+ // Canvas setup
5
+ const canvas = document.getElementById('canvas');
6
+ const ctx = canvas.getContext('2d');
7
+
8
+ // Set canvas size to window size
9
+ function resizeCanvas() {
10
+ canvas.width = window.innerWidth;
11
+ canvas.height = window.innerHeight;
12
+ centerX = canvas.width / 2;
13
+ centerY = canvas.height / 2;
14
+ }
15
+
16
+ resizeCanvas();
17
+ window.addEventListener('resize', resizeCanvas);
18
+
19
+ // Center coordinates
20
+ let centerX = canvas.width / 2;
21
+ let centerY = canvas.height / 2;
22
+
23
+ // Animation controls
24
+ let animationRunning = true;
25
+ let showParticles = true;
26
+ let showConnections = true;
27
+
28
+ // Brainwave and field controls
29
+ let brainwaveState = "alpha"; // default
30
+ let frequencyMultiplier = 1.0;
31
+ let amplitudeMultiplier = 1.0;
32
+ let coherenceMultiplier = 1.0;
33
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  // Harmonic patterns
35
+ let activeHarmonics = null; // none, fibonacci, goldenRatio, prime
36
+
37
+ // AI response system
38
+ let aiThoughts = [];
39
+ let aiResponseLastUpdate = 0;
40
+
41
+ // Configuration object for system behavior
42
+ const config = {
43
+ brainRadius: Math.min(canvas.width, canvas.height) * 0.05,
44
+ brainColor: '#2271ff',
45
+ brainPulseSpeed: 0.005,
46
+ brainPulseRange: 0.3,
47
+ fieldMaxRadius: Math.min(canvas.width, canvas.height) * 0.4,
48
+ fieldWaveSpeed: 0.6,
49
+ particleCount: 150,
50
+ particleRadius: 2,
51
+ particleSpeed: 0.5,
52
+ connectionOpacity: 0.15,
53
+ connectionThreshold: 100,
54
+ maxConnections: 3,
55
+ brainwaves: {
56
+ delta: { pulseSpeed: 0.002, waveSpeed: 0.3, color: '#3a5ad9', aiDescription: "Deep, unconscious processing." },
57
+ theta: { pulseSpeed: 0.004, waveSpeed: 0.5, color: '#4f7ff5', aiDescription: "Meditative state." },
58
+ alpha: { pulseSpeed: 0.006, waveSpeed: 0.7, color: '#2271ff', aiDescription: "Relaxed, creative state." },
59
+ beta: { pulseSpeed: 0.01, waveSpeed: 1.0, color: '#008aff', aiDescription: "Active thinking state." },
60
+ gamma: { pulseSpeed: 0.015, waveSpeed: 1.5, color: '#00c8ff', aiDescription: "Higher consciousness state." }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
+ };
63
+
64
+ let brain = { pulsePhase: 0 };
65
+ let particles = [];
66
+
67
+ // Initialize particles
68
+ for (let i = 0; i < config.particleCount; i++) {
69
+ particles.push({
70
+ x: Math.random() * canvas.width,
71
+ y: Math.random() * canvas.height,
72
+ radius: config.particleRadius,
73
+ speed: config.particleSpeed,
74
+ angle: Math.random() * Math.PI * 2,
75
+ color: config.brainColor
76
+ });
77
+ }
78
+
79
+ // Setup UI Controls
80
+ function setupControls() {
81
+ console.log("Setting up controls...");
82
+
83
+ const brainwaveButtons = document.querySelectorAll('.brainwave-buttons button');
84
+ brainwaveButtons.forEach(button => {
85
+ button.addEventListener('click', function() {
86
+ setBrainwaveState(this.id.replace('Brain', ''));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  });
88
+ });
89
+
90
+ // Sliders
91
+ document.getElementById('frequencySlider').addEventListener('input', function() {
92
+ frequencyMultiplier = parseFloat(this.value);
93
+ document.getElementById('frequencyValue').textContent = frequencyMultiplier.toFixed(1);
94
+ });
95
+
96
+ document.getElementById('amplitudeSlider').addEventListener('input', function() {
97
+ amplitudeMultiplier = parseFloat(this.value);
98
+ document.getElementById('amplitudeValue').textContent = amplitudeMultiplier.toFixed(1);
99
+ });
100
+
101
+ document.getElementById('coherenceSlider').addEventListener('input', function() {
102
+ coherenceMultiplier = parseFloat(this.value);
103
+ document.getElementById('coherenceValue').textContent = coherenceMultiplier.toFixed(1);
104
+ });
105
+
106
+ // Play/Pause Button
107
+ document.getElementById('togglePlay').addEventListener('click', function() {
108
+ animationRunning = !animationRunning;
109
+ this.textContent = animationRunning ? 'Pause' : 'Play';
110
+ if (animationRunning) animate();
111
+ });
112
+ }
113
+
114
+ // Function to update brainwave state
115
+ function setBrainwaveState(state) {
116
+ console.log("Switching to brainwave state:", state);
117
+
118
+ brainwaveState = state;
119
+ const brainwaveConfig = config.brainwaves[state];
120
+
121
+ config.brainPulseSpeed = brainwaveConfig.pulseSpeed;
122
+ config.fieldWaveSpeed = brainwaveConfig.waveSpeed;
123
+ config.brainColor = brainwaveConfig.color;
124
+
125
+ updateAIResponse();
126
+ }
127
+
128
+ // AI Response System
129
+ function updateAIResponse() {
130
+ console.log("Updating AI response...");
131
+ const thought = config.brainwaves[brainwaveState].aiDescription;
132
+ aiThoughts.push(thought);
133
+ if (aiThoughts.length > 3) aiThoughts.shift();
134
+ document.getElementById('aiResponse').textContent = aiThoughts.join("\n\n");
135
+ }
136
+
137
+ // Draw Brain
138
+ function drawBrain() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  ctx.beginPath();
140
+ ctx.arc(centerX, centerY, config.brainRadius, 0, Math.PI * 2);
141
+ ctx.fillStyle = config.brainColor;
142
  ctx.fill();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
+
145
+ // Draw Particles
146
+ function drawParticles() {
147
+ for (let i = 0; i < particles.length; i++) {
148
+ const p = particles[i];
149
+
150
+ // Move particles
151
+ if (animationRunning) {
152
+ p.x += Math.cos(p.angle) * p.speed;
153
+ p.y += Math.sin(p.angle) * p.speed;
154
+
155
+ if (p.x < 0) p.x = canvas.width;
156
+ if (p.x > canvas.width) p.x = 0;
157
+ if (p.y < 0) p.y = canvas.height;
158
+ if (p.y > canvas.height) p.y = 0;
159
+ }
160
+
161
+ // Draw particles
162
+ ctx.beginPath();
163
+ ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
164
+ ctx.fillStyle = p.color;
165
+ ctx.fill();
166
+ }
167
+ }
168
+
169
+ // Animation Loop
170
+ function animate() {
171
+ if (!animationRunning) return;
172
+
173
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
174
+
175
+ drawBrain();
176
+ drawParticles();
177
+
178
+ requestAnimationFrame(animate);
179
+ }
180
+
181
+ // Initialize
182
+ setupControls();
183
+ setBrainwaveState('alpha');
184
+ updateAIResponse();
185
+
186
+ // Start animation
187
+ console.log("Starting animation...");
188
+ animate();
189
+ });