diff --git a/src/Components/BackgroundCanvas/BackgroundCanvas.jsx b/src/Components/BackgroundCanvas/BackgroundCanvas.jsx index ff671f1..c47e6c2 100644 --- a/src/Components/BackgroundCanvas/BackgroundCanvas.jsx +++ b/src/Components/BackgroundCanvas/BackgroundCanvas.jsx @@ -127,35 +127,44 @@ const BackgroundCanvas = ({ theme = 'light' }) => { camera.acceleration.z *= 0.9; }; - const initCanvas = () => { - const canvas = canvasRef.current; - if (!canvas) return; +const initCanvas = () => { + const canvas = canvasRef.current; + if (!canvas) return; - const ctx = canvas.getContext('2d'); - const view = { - width: window.innerWidth, - height: window.innerHeight, - }; - - canvas.width = view.width; - canvas.height = view.height; - - worldRef.current = { - width: view.width * 2, - height: view.height * 2, - }; - - cameraRef.current = new Camera( - { - x: worldRef.current.width / 2, - y: worldRef.current.height / 2, - }, - 1 - ); - - jointsRef.current = generateJoints(300, worldRef.current.width, worldRef.current.height); + const ctx = canvas.getContext('2d'); + const view = { + width: window.innerWidth, + height: window.innerHeight, }; + canvas.width = view.width; + canvas.height = view.height; + + worldRef.current = { + width: view.width * 2, + height: view.height * 2, + }; + + cameraRef.current = new Camera( + { + x: worldRef.current.width / 2, + y: worldRef.current.height / 2, + }, + 1 + ); + + const isMobile = window.innerWidth < 768; + const numberOfJoints = isMobile ? 80 : 300; + jointsRef.current = generateJoints(numberOfJoints, worldRef.current.width, worldRef.current.height); + + if (isMobile) { + jointsRef.current.forEach(joint => { + joint.bone_length = 120; + joint.speed = 0.4; + }); + } +}; + const animate = () => { const canvas = canvasRef.current; if (!canvas) return;