Changed around line 1
+ class Node {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ this.vx = (Math.random() - 0.5) * 2;
+ this.vy = (Math.random() - 0.5) * 2;
+ this.radius = Math.random() * 2 + 1;
+ }
+
+ update(width, height) {
+ this.x += this.vx;
+ this.y += this.vy;
+
+ if (this.x < 0 || this.x > width) this.vx *= -1;
+ if (this.y < 0 || this.y > height) this.vy *= -1;
+ }
+ }
+
+ class NodesAnimation {
+ constructor() {
+ this.canvas = document.getElementById('nodesCanvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.nodes = [];
+ this.mouse = { x: 0, y: 0 };
+ this.connectionDistance = 150;
+ this.init();
+ }
+
+ init() {
+ this.resize();
+ this.createNodes(50);
+ this.bindEvents();
+ this.animate();
+ }
+
+ resize() {
+ this.width = window.innerWidth;
+ this.height = window.innerHeight;
+ this.canvas.width = this.width * window.devicePixelRatio;
+ this.canvas.height = this.height * window.devicePixelRatio;
+ this.ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
+ }
+
+ createNodes(count) {
+ for (let i = 0; i < count; i++) {
+ this.nodes.push(new Node(
+ Math.random() * this.width,
+ Math.random() * this.height
+ ));
+ }
+ }
+
+ bindEvents() {
+ window.addEventListener('resize', () => this.resize());
+ window.addEventListener('mousemove', (e) => {
+ this.mouse.x = e.clientX;
+ this.mouse.y = e.clientY;
+ });
+ }
+
+ drawConnections() {
+ this.ctx.beginPath();
+ this.ctx.strokeStyle = 'rgba(255, 255, 255, 0.15)';
+
+ for (let i = 0; i < this.nodes.length; i++) {
+ for (let j = i + 1; j < this.nodes.length; j++) {
+ const dx = this.nodes[i].x - this.nodes[j].x;
+ const dy = this.nodes[i].y - this.nodes[j].y;
+ const distance = Math.sqrt(dx * dx + dy * dy);
+
+ if (distance < this.connectionDistance) {
+ const opacity = 1 - (distance / this.connectionDistance);
+ this.ctx.strokeStyle = `rgba(255, 255, 255, ${opacity * 0.15})`;
+ this.ctx.beginPath();
+ this.ctx.moveTo(this.nodes[i].x, this.nodes[i].y);
+ this.ctx.lineTo(this.nodes[j].x, this.nodes[j].y);
+ this.ctx.stroke();
+ }
+ }
+ }
+ }
+
+ animate() {
+ this.ctx.clearRect(0, 0, this.width, this.height);
+
+ this.nodes.forEach(node => {
+ node.update(this.width, this.height);
+
+ this.ctx.beginPath();
+ this.ctx.arc(node.x, node.y, node.radius, 0, Math.PI * 2);
+ this.ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
+ this.ctx.fill();
+ });
+
+ this.drawConnections();
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new NodesAnimation();
+ });