From 23e32c1e186881b76ed2d76c09ee78412e6f6d4c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 12:21:01 +0000 Subject: [PATCH] Revise network animation Updated the network animation to enhance its elegance and visual appeal. [skip gpt_engineer] --- .../game/animations/NetworkAnimation.tsx | 157 +++++++++++------- 1 file changed, 100 insertions(+), 57 deletions(-) diff --git a/src/components/game/animations/NetworkAnimation.tsx b/src/components/game/animations/NetworkAnimation.tsx index 1fe77b0..e26f82d 100644 --- a/src/components/game/animations/NetworkAnimation.tsx +++ b/src/components/game/animations/NetworkAnimation.tsx @@ -1,90 +1,112 @@ -import React from 'react'; +import React, { useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; interface Node { id: number; - baseX: number; - baseY: number; + x: number; + y: number; + size: number; + delay: number; } export const NetworkAnimation = ({ className = '' }: { className?: string }) => { - const nodes: Node[] = Array.from({ length: 6 }, (_, i) => { - const row = Math.floor(i / 2); - const col = i % 2; - return { - id: i, - baseX: 30 + col * 40, - baseY: 25 + row * 25, - }; - }); + const containerRef = useRef(null); + + // Generate nodes with different sizes and positions + const nodes: Node[] = Array.from({ length: 12 }, (_, i) => ({ + id: i, + x: 20 + Math.random() * 60, // Random position between 20-80% + y: 20 + Math.random() * 60, + size: 2 + Math.random() * 2, // Random size between 2-4 + delay: i * 0.1 // Staggered animation delay + })); + + // Create pairs of nodes for connections + const connections = nodes.flatMap((node, i) => + nodes.slice(i + 1).map(otherNode => ({ + id: `${node.id}-${otherNode.id}`, + from: node, + to: otherNode, + opacity: Math.random() * 0.3 + 0.1 // Random opacity between 0.1-0.4 + })) + ); return ( -
- - {nodes.map((node1) => - nodes - .filter((node2) => node2.id !== node1.id) - .map((node2) => ( - 0.5 ? 10 : -10)}%`], - y1: [`${node1.baseY}%`, `${node1.baseY + (Math.random() > 0.5 ? 10 : -10)}%`], - x2: [`${node2.baseX}%`, `${node2.baseX + (Math.random() > 0.5 ? 10 : -10)}%`], - y2: [`${node2.baseY}%`, `${node2.baseY + (Math.random() > 0.5 ? 10 : -10)}%`], - }} - transition={{ - duration: 4, - repeat: Infinity, - repeatType: "mirror", - ease: "easeInOut" - }} - /> - )) - )} +
+ + {/* Render connections between nodes */} + {connections.map(({ id, from, to, opacity }) => ( + + ))} + {/* Render nodes */} {nodes.map((node) => ( 0.5 ? 10 : -10)}%`, - `${node.baseX}%`, + -10, + 10, + -5, + 5, + 0 ], y: [ - `${node.baseY}%`, - `${node.baseY + (Math.random() > 0.5 ? 10 : -10)}%`, - `${node.baseY}%`, - ], + -5, + 5, + -10, + 10, + 0 + ] }} transition={{ - duration: 6, + duration: 8, repeat: Infinity, repeatType: "reverse", ease: "easeInOut", - delay: node.id * 0.2, + delay: node.delay, }} > + {/* Core node */} }} /> + {/* Outer glow */} duration: 3, repeat: Infinity, ease: "easeInOut", - delay: node.id * 0.1, + delay: node.delay * 0.5, }} /> + + {/* Particle effects */} + {Array.from({ length: 3 }).map((_, i) => ( + + ))} ))}