diff --git a/site/src/routes/+page.svelte b/site/src/routes/+page.svelte index 6c0e2ed..11d0c2e 100644 --- a/site/src/routes/+page.svelte +++ b/site/src/routes/+page.svelte @@ -2,7 +2,7 @@ import { onMount } from "svelte"; import Lenis from "lenis"; - function createSmoothPath(points) { + function createSmoothPath(points: Array<{ x: number; y: number }>) { if (points.length < 2) return ""; // Create smooth curves that flow horizontally through points @@ -109,7 +109,7 @@ return path; } - function getPointAlongPath(points, percentage) { + function getPointAlongPath(points: Array<{ x: number; y: number }>, percentage: number) { if (points.length < 2) return { x: 0, y: 0, angle: 0 }; // Generate the same control points as the path @@ -230,7 +230,7 @@ let currentAirplaneProgress = 0; - let animationFrameId = null; + let animationFrameId: number | null = null; let isFlipped = false; function updateAirplanePosition() { @@ -267,26 +267,7 @@ // Determine movement direction const movingForward = currentAirplaneProgress > previousProgress; - // Check for point transitions and handle flipping - // Point 2 is at ~0.33 progress, Point 3 is at ~0.67 progress - const point2Progress = 1/3; - const point3Progress = 2/3; - - if (movingForward) { - // Moving forward: flip at point 2, unflip at point 3 - if (previousProgress < point2Progress && currentAirplaneProgress >= point2Progress) { - isFlipped = true; - } else if (previousProgress < point3Progress && currentAirplaneProgress >= point3Progress) { - isFlipped = false; - } - } else { - // Moving backward: flip at point 3, unflip at point 2 - if (previousProgress > point3Progress && currentAirplaneProgress <= point3Progress) { - isFlipped = true; - } else if (previousProgress > point2Progress && currentAirplaneProgress <= point2Progress) { - isFlipped = false; - } - } + // Get points for path calculation const points = []; @@ -306,6 +287,15 @@ airplane.style.left = `${airplanePos.x}px`; airplane.style.top = `${airplanePos.y}px`; + // Check if rotation angle is greater than 90 degrees (plane is upside down) + // Normalize angle to -180 to 180 range + let normalizedAngle = airplanePos.angle; + while (normalizedAngle > 180) normalizedAngle -= 360; + while (normalizedAngle < -180) normalizedAngle += 360; + + // Flip plane if angle is outside -90 to 90 degree range (keeps plane right side up) + isFlipped = Math.abs(normalizedAngle) > 90; + // Apply vertical flip if needed const verticalFlip = isFlipped ? ' scaleY(-1)' : ''; airplane.style.transform = `translate(-50%, calc(-50% - 0.5rem)) rotate(${airplanePos.angle}deg)${verticalFlip}`; @@ -379,7 +369,8 @@