From cb56567f4e18a453aa4ef30161da8763baf204f0 Mon Sep 17 00:00:00 2001 From: Timo Erdelt Date: Wed, 29 Nov 2023 16:07:05 +0100 Subject: [PATCH 1/2] feat(boxes): improve animation of cyan box in header --- src/components/CyanAmberHeaderBox.tsx | 44 +++++++++++++++++++++++++-- src/components/HeaderAndMainClaim.tsx | 4 +-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/components/CyanAmberHeaderBox.tsx b/src/components/CyanAmberHeaderBox.tsx index 4a0d865..4866dfa 100644 --- a/src/components/CyanAmberHeaderBox.tsx +++ b/src/components/CyanAmberHeaderBox.tsx @@ -1,7 +1,12 @@ -import { ReactNode } from 'react' +import { ReactNode, useEffect, useState } from 'react' import { cn } from '@/lib/utils' +const initBottomRightX = 1333.88 +const initBottomRightY = 777.16 +const initBottomLeftX = 90.69 +const initBottomLeftY = 850 + export default function CyanAmberHeaderBox({ children, className, @@ -9,11 +14,46 @@ export default function CyanAmberHeaderBox({ children: ReactNode className: string }) { + const [bottomRightX, setBottomRightX] = useState(initBottomRightX) + const [bottomRightY, setBottomRightY] = useState(initBottomRightY) + const [bottomLeftX, setBottomLeftX] = useState(initBottomLeftX) + const [bottomLeftY, setBottomLeftY] = useState(initBottomLeftY) + + useEffect(() => { + let angle1 = 0, + angle2 = 0 + + // Idea: Let bottom corners rotate in circles with different radios and different cycling time + function updateClipPath() { + const radius1 = 15 // radius of the circle of bottom right + const radius2 = 10 // radius of the circle of bottom left + + // Calculate new positions for the bottom corners and update clip path + setBottomRightX(initBottomRightX + Math.cos(angle1) * radius1) + setBottomRightY(initBottomRightY + Math.sin(angle1) * radius1) + setBottomLeftX(initBottomLeftX + Math.cos(angle2) * radius2) + setBottomLeftY(initBottomLeftY + Math.sin(angle2) * radius2) + + // Update angles for asynchronous movement + angle1 += 0.00413 + angle2 -= 0.00652 // Different increment for asynchronous movement + + requestAnimationFrame(updateClipPath) + } + + updateClipPath() + }, []) + return (
-
+
{children}
diff --git a/src/components/HeaderAndMainClaim.tsx b/src/components/HeaderAndMainClaim.tsx index a484a7b..5204ac5 100644 --- a/src/components/HeaderAndMainClaim.tsx +++ b/src/components/HeaderAndMainClaim.tsx @@ -56,7 +56,7 @@ export default function HeaderAndMainClaim() { {headerOpacity > 0 && (
@@ -65,7 +65,7 @@ export default function HeaderAndMainClaim() { {scrollDownButtonOpacity > 0 && (