import React, { useEffect, useState } from "react"; import { motion } from "framer-motion"; const Background = () => { const [gridSize, setGridSize] = useState({ cols: 12, rows: 6 }); const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); const [path, setPath] = useState([]); useEffect(() => { const updateGrid = () => { const width = window.innerWidth; const height = window.innerHeight; const cols = Math.max(8, Math.floor(width / 100)); // 100px-es cellák const rows = Math.max(5, Math.floor(height / 100)); // 100px-es cellák setGridSize({ cols, rows }); }; const handleMouseMove = (e) => { setMousePos({ x: e.clientX, y: e.clientY }); }; updateGrid(); window.addEventListener("resize", updateGrid); window.addEventListener("mousemove", handleMouseMove); return () => { window.removeEventListener("resize", updateGrid); window.removeEventListener("mousemove", handleMouseMove); }; }, []); useEffect(() => { const interval = setInterval(() => { const newCol = Math.floor(Math.random() * gridSize.cols); const newRow = Math.floor(Math.random() * gridSize.rows); setPath((prevPath) => { const newPath = [...prevPath, { col: newCol, row: newRow, opacity: 1 }]; // Új pont hozzáadása if (newPath.length > 10) { newPath.shift(); // Max 10 pont az útvonalon } return newPath; }); }, 500); // Új pont hozzáadása minden 500ms-ben // Az útvonal pontjainak fokozatos eltűnése const fadeInterval = setInterval(() => { setPath((prevPath) => prevPath.map((point) => ({ ...point, opacity: Math.max(0, point.opacity - 0.05), // Fokozatosan csökkentjük az opacity-t })).filter((point) => point.opacity > 0) // Eltávolítjuk a teljesen eltűnt pontokat ); }, 100); // Opacity frissítése minden 100ms-ben return () => { clearInterval(interval); clearInterval(fadeInterval); }; }, [gridSize]); return (