Changed around line 1
+ class Particle {
+ constructor(canvas) {
+ this.canvas = canvas;
+ this.reset();
+ }
+
+ reset() {
+ this.x = Math.random() * this.canvas.width;
+ this.y = Math.random() * this.canvas.height;
+ this.vx = (Math.random() - 0.5) * 2;
+ this.vy = (Math.random() - 0.5) * 2;
+ this.radius = Math.random() * 2 + 1;
+ }
+
+ update(speed) {
+ this.x += this.vx * speed;
+ this.y += this.vy * speed;
+
+ if (this.x < 0 || this.x > this.canvas.width) this.vx *= -1;
+ if (this.y < 0 || this.y > this.canvas.height) this.vy *= -1;
+ }
+ }
+
+ class ParticleSystem {
+ constructor() {
+ this.canvas = document.getElementById('particleCanvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.particles = [];
+ this.colorMode = 'blue';
+ this.particleCount = 200;
+ this.speed = 5;
+ this.connectionRadius = 100;
+
+ this.resize();
+ this.init();
+ this.setupEventListeners();
+ this.animate();
+ }
+
+ resize() {
+ this.canvas.width = window.innerWidth;
+ this.canvas.height = window.innerHeight;
+ }
+
+ init() {
+ this.particles = [];
+ for (let i = 0; i < this.particleCount; i++) {
+ this.particles.push(new Particle(this.canvas));
+ }
+ }
+
+ setupEventListeners() {
+ window.addEventListener('resize', () => this.resize());
+
+ document.getElementById('particleCount').addEventListener('input', (e) => {
+ this.particleCount = parseInt(e.target.value);
+ this.init();
+ });
+
+ document.getElementById('particleSpeed').addEventListener('input', (e) => {
+ this.speed = parseInt(e.target.value);
+ });
+
+ document.getElementById('connectionRadius').addEventListener('input', (e) => {
+ this.connectionRadius = parseInt(e.target.value);
+ });
+
+ document.getElementById('colorToggle').addEventListener('click', () => {
+ this.colorMode = this.colorMode === 'blue' ? 'rainbow' : 'blue';
+ });
+ }
+
+ getColor(distance) {
+ if (this.colorMode === 'blue') {
+ const alpha = 1 - (distance / this.connectionRadius);
+ return `rgba(0, 159, 253, ${alpha})`;
+ } else {
+ const hue = (distance / this.connectionRadius) * 360;
+ return `hsla(${hue}, 100%, 50%, ${1 - distance / this.connectionRadius})`;
+ }
+ }
+
+ draw() {
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+
+ for (let i = 0; i < this.particles.length; i++) {
+ const p1 = this.particles[i];
+
+ for (let j = i + 1; j < this.particles.length; j++) {
+ const p2 = this.particles[j];
+ const dx = p1.x - p2.x;
+ const dy = p1.y - p2.y;
+ const distance = Math.sqrt(dx * dx + dy * dy);
+
+ if (distance < this.connectionRadius) {
+ this.ctx.beginPath();
+ this.ctx.strokeStyle = this.getColor(distance);
+ this.ctx.lineWidth = 1;
+ this.ctx.moveTo(p1.x, p1.y);
+ this.ctx.lineTo(p2.x, p2.y);
+ this.ctx.stroke();
+ }
+ }
+
+ this.ctx.beginPath();
+ this.ctx.fillStyle = '#ffffff';
+ this.ctx.arc(p1.x, p1.y, p1.radius, 0, Math.PI * 2);
+ this.ctx.fill();
+ }
+ }
+
+ animate() {
+ this.particles.forEach(p => p.update(this.speed));
+ this.draw();
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new ParticleSystem();
+ });