Implement a random blinking effect for the nodes in the NetworkAnimation component to enhance visual dynamics.
[skip gpt_engineer]
Этот коммит содержится в:
gpt-engineer-app[bot] 2024-12-15 12:55:54 +00:00
родитель dbd515b623
Коммит e207ec15f1

Просмотреть файл

@ -7,18 +7,20 @@ interface Node {
y: number; y: number;
size: number; size: number;
delay: number; delay: number;
isGreen: boolean; // New property to determine node color
} }
export const NetworkAnimation = ({ className = '' }: { className?: string }) => { export const NetworkAnimation = ({ className = '' }: { className?: string }) => {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
// Generate nodes with different sizes and positions // Generate nodes with different sizes, positions, and colors
const nodes: Node[] = Array.from({ length: 15 }, (_, i) => ({ const nodes: Node[] = Array.from({ length: 15 }, (_, i) => ({
id: i, id: i,
x: 20 + Math.random() * 60, x: 20 + Math.random() * 60,
y: 20 + Math.random() * 60, y: 20 + Math.random() * 60,
size: 3 + Math.random() * 3, // Larger nodes (3-6px) size: 3 + Math.random() * 3,
delay: i * 0.1 delay: i * 0.1,
isGreen: Math.random() > 0.7 // 30% chance of being green
})); }));
// Create pairs of nodes for connections // Create pairs of nodes for connections
@ -27,7 +29,7 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
id: `${node.id}-${otherNode.id}`, id: `${node.id}-${otherNode.id}`,
from: node, from: node,
to: otherNode, to: otherNode,
opacity: Math.random() * 0.5 + 0.2 // Higher opacity (0.2-0.7) opacity: Math.random() * 0.5 + 0.2
})) }))
); );
@ -37,7 +39,6 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
className={`relative w-full h-40 overflow-hidden bg-black/20 rounded-lg ${className}`} className={`relative w-full h-40 overflow-hidden bg-black/20 rounded-lg ${className}`}
> >
<svg className="absolute inset-0 w-full h-full"> <svg className="absolute inset-0 w-full h-full">
{/* Render connections between nodes */}
{connections.map(({ id, from, to, opacity }) => ( {connections.map(({ id, from, to, opacity }) => (
<motion.line <motion.line
key={id} key={id}
@ -45,13 +46,13 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
y1={`${from.y}%`} y1={`${from.y}%`}
x2={`${to.x}%`} x2={`${to.x}%`}
y2={`${to.y}%`} y2={`${to.y}%`}
stroke="rgba(255, 215, 0, 0.4)" // Brighter connections stroke={`rgba(${from.isGreen && to.isGreen ? '0, 255, 0' : '255, 215, 0'}, 0.4)`}
strokeWidth="1" // Thicker lines strokeWidth="1"
initial={{ opacity: 0, pathLength: 0 }} initial={{ opacity: 0, pathLength: 0 }}
animate={{ animate={{
opacity: [0, opacity, opacity/2], opacity: [0, opacity, opacity/2],
pathLength: [0, 1, 1], pathLength: [0, 1, 1],
strokeWidth: [1, 2, 1] // Pulsing line thickness strokeWidth: [1, 2, 1]
}} }}
transition={{ transition={{
duration: 2, duration: 2,
@ -64,7 +65,6 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
))} ))}
</svg> </svg>
{/* Render nodes */}
{nodes.map((node) => ( {nodes.map((node) => (
<motion.div <motion.div
key={node.id} key={node.id}
@ -79,20 +79,8 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
animate={{ animate={{
scale: [0, 1.2, 1], scale: [0, 1.2, 1],
opacity: [0, 1, 0.8], opacity: [0, 1, 0.8],
x: [ x: [-15, 15, -10, 10, 0],
-15, y: [-10, 10, -15, 15, 0]
15,
-10,
10,
0
],
y: [
-10,
10,
-15,
15,
0
]
}} }}
transition={{ transition={{
duration: 6, duration: 6,
@ -104,13 +92,13 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
> >
{/* Core node */} {/* Core node */}
<motion.div <motion.div
className="absolute w-full h-full rounded-full bg-yellow-400" // Brighter yellow className={`absolute w-full h-full rounded-full ${node.isGreen ? 'bg-green-400' : 'bg-yellow-400'}`}
animate={{ animate={{
scale: [1, 1.5, 1], scale: [1, 1.5, 1],
opacity: [0.8, 1, 0.8], opacity: node.isGreen ? [0.8, 0.2, 0.8] : [0.8, 1, 0.8],
}} }}
transition={{ transition={{
duration: 1.5, duration: node.isGreen ? 1 : 1.5,
repeat: Infinity, repeat: Infinity,
ease: "easeInOut", ease: "easeInOut",
}} }}
@ -118,9 +106,9 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
{/* Outer glow */} {/* Outer glow */}
<motion.div <motion.div
className="absolute w-full h-full rounded-full bg-yellow-400/40" // Brighter glow className={`absolute w-full h-full rounded-full ${node.isGreen ? 'bg-green-400/40' : 'bg-yellow-400/40'}`}
animate={{ animate={{
scale: [1, 4, 1], // Larger glow scale: [1, 4, 1],
opacity: [0.4, 0, 0.4], opacity: [0.4, 0, 0.4],
}} }}
transition={{ transition={{
@ -135,12 +123,14 @@ export const NetworkAnimation = ({ className = '' }: { className?: string }) =>
{Array.from({ length: 4 }).map((_, i) => ( {Array.from({ length: 4 }).map((_, i) => (
<motion.div <motion.div
key={i} key={i}
className="absolute w-1.5 h-1.5 rounded-full bg-yellow-300/30" // Larger, brighter particles className={`absolute w-1.5 h-1.5 rounded-full ${
node.isGreen ? 'bg-green-300/30' : 'bg-yellow-300/30'
}`}
animate={{ animate={{
x: [0, (i - 1.5) * 15], // Wider spread x: [0, (i - 1.5) * 15],
y: [0, (i - 1.5) * 15], y: [0, (i - 1.5) * 15],
scale: [0, 1.5, 0], // Larger scale scale: [0, 1.5, 0],
opacity: [0, 0.7, 0], // Higher opacity opacity: [0, 0.7, 0],
}} }}
transition={{ transition={{
duration: 1.5, duration: 1.5,