From 116e4747c25b46504da667769ffe214b01ae00b1 Mon Sep 17 00:00:00 2001 From: feco Date: Sat, 21 Nov 2026 21:23:52 +0000 Subject: [PATCH] Night sky background with shooting stars on every page Faint twinkling stars and, on average every 6 seconds, a gold shooting star, on a fixed canvas behind all content: anything with its own background (bands, cards, the header) covers it, so the meteor passes under them. With reduced motion only still stars are drawn. Replaces the home page hero's own starfield. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL --- services/frontend/src/app/Landing.tsx | 20 --- services/frontend/src/app/globals.css | 4 + services/frontend/src/app/layout.tsx | 2 + services/frontend/src/components/NightSky.tsx | 143 ++++++++++++++++++ 4 files changed, 149 insertions(+), 20 deletions(-) create mode 100644 services/frontend/src/components/NightSky.tsx diff --git a/services/frontend/src/app/Landing.tsx b/services/frontend/src/app/Landing.tsx index 30787f8..ea2f624 100644 --- a/services/frontend/src/app/Landing.tsx +++ b/services/frontend/src/app/Landing.tsx @@ -12,21 +12,6 @@ import type { AnalysisContent, ChartResult } from "@/lib/types"; /** The cards fanned out next to the tarot line (after a card back). */ const TAROT_CARDS = ["major-2", "major-17"].map((id) => tarotCard(id)).filter((c) => c !== undefined); -// A quiet starfield, the same on every render. -const STARS = (() => { - let seed = 7; - const rnd = () => { - seed = (seed * 9301 + 49297) % 233280; - return seed / 233280; - }; - return Array.from({ length: 70 }, (_, i) => ({ - x: (rnd() * 1000).toFixed(1), - y: (rnd() * 600).toFixed(1), - r: (0.6 + rnd() * 1.4).toFixed(1), - t: i % 5, - })); -})(); - const MONTHS = ["márc", "ápr", "máj", "jún", "júl", "aug", "szept", "okt", "nov", "dec", "jan", "febr"]; /** Points of a ring of the comparison picture. */ @@ -68,11 +53,6 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
-
Születési képlet · Éves előrejelzés · Kapcsolat diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index 1d79442..e93726b 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -26,6 +26,10 @@ * { box-sizing: border-box; } html, body { margin: 0; } +/* The night sky behind everything (components/NightSky.tsx): drawn over the + page background, under all content, so anything with its own background + covers it. */ +.night-sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; } body { min-height: 100vh; overflow-x: clip; /* nothing may push the page sideways on a phone */ diff --git a/services/frontend/src/app/layout.tsx b/services/frontend/src/app/layout.tsx index 814821a..6e15466 100644 --- a/services/frontend/src/app/layout.tsx +++ b/services/frontend/src/app/layout.tsx @@ -2,6 +2,7 @@ import type { Metadata } from "next"; import { Cormorant_Garamond, Inter } from "next/font/google"; import { Suspense } from "react"; +import { NightSky } from "@/components/NightSky"; import { PaymentReturn } from "@/components/PaymentReturn"; import { SiteHeader } from "@/components/SiteHeader"; import { getMe } from "@/lib/server"; @@ -30,6 +31,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo return ( + {me && } {children} {me && ( diff --git a/services/frontend/src/components/NightSky.tsx b/services/frontend/src/components/NightSky.tsx new file mode 100644 index 0000000..5b01019 --- /dev/null +++ b/services/frontend/src/components/NightSky.tsx @@ -0,0 +1,143 @@ +"use client"; + +import { useEffect, useRef } from "react"; + +/** The meteor's colour (warm gold, like the site's accent) and its head. */ +const TINT = [236, 205, 140]; +/** On average one meteor this often (seconds); each gap is 50–150% of it. */ +const EVERY = 6; + +/** + * The site's background: faint twinkling stars and, every few seconds, a + * shooting star. A fixed canvas behind all content, so anything with its own + * background (bands, cards, the header) covers it and the meteor passes + * under them. With "reduce motion" set, only still stars are drawn. + */ +export function NightSky() { + const ref = useRef(null); + + useEffect(() => { + const canvas = ref.current; + const ctx = canvas?.getContext("2d"); + if (!canvas || !ctx) return; + const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches; + + type Star = { x: number; y: number; r: number; base: number; phase: number; rate: number }; + type Meteor = { x: number; y: number; dx: number; dy: number; len: number; life: number; span: number; width: number }; + let w = 0; + let h = 0; + let stars: Star[] = []; + const meteors: Meteor[] = []; + + function resize() { + const dpr = Math.min(window.devicePixelRatio || 1, 2); + w = canvas!.clientWidth; + h = canvas!.clientHeight; + canvas!.width = Math.round(w * dpr); + canvas!.height = Math.round(h * dpr); + ctx!.setTransform(dpr, 0, 0, dpr, 0, 0); + // About one star per 9000 px². + stars = Array.from({ length: Math.round((w * h) / 9000) }, () => ({ + x: Math.random() * w, + y: Math.random() * h, + r: Math.random() < 0.85 ? 0.5 + Math.random() * 0.7 : 1.1 + Math.random() * 0.6, + base: 0.12 + Math.random() * 0.3, + phase: Math.random() * Math.PI * 2, + rate: 0.4 + Math.random() * 0.9, + })); + if (reduced) drawStars(0); + } + + /** Enters in the upper part of the screen and falls down and to the left at a shallow angle. */ + function spawn() { + const angle = ((200 + Math.random() * 18) * Math.PI) / 180; + const speed = (w > 700 ? 900 : 620) * (0.85 + Math.random() * 0.3); + meteors.push({ + x: w * (0.35 + Math.random() * 0.75), + y: -20 + Math.random() * h * 0.35, + dx: Math.cos(angle) * speed, + dy: -Math.sin(angle) * speed, + len: (w > 700 ? 190 : 130) * (0.8 + Math.random() * 0.5), + life: 0, + span: 0.75 + Math.random() * 0.45, + width: 1.2 + Math.random() * 0.8, + }); + } + + function drawStars(t: number) { + ctx!.clearRect(0, 0, w, h); + ctx!.fillStyle = "#ece6d8"; + for (const s of stars) { + ctx!.globalAlpha = Math.max(0.04, reduced ? s.base : s.base + Math.sin(t * s.rate + s.phase) * 0.12); + ctx!.beginPath(); + ctx!.arc(s.x, s.y, s.r, 0, Math.PI * 2); + ctx!.fill(); + } + ctx!.globalAlpha = 1; + } + + function drawMeteor(m: Meteor) { + const p = m.life / m.span; + // Fades in fast, burns, then fades out. + const fade = p < 0.15 ? p / 0.15 : p > 0.7 ? Math.max(0, (1 - p) / 0.3) : 1; + const [r, g, b] = TINT; + const norm = Math.hypot(m.dx, m.dy); + const tx = m.x - (m.dx / norm) * m.len; + const ty = m.y - (m.dy / norm) * m.len; + const tail = ctx!.createLinearGradient(m.x, m.y, tx, ty); + tail.addColorStop(0, `rgba(255, 250, 235, ${0.95 * fade})`); + tail.addColorStop(0.12, `rgba(${r}, ${g}, ${b}, ${0.75 * fade})`); + tail.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`); + ctx!.strokeStyle = tail; + ctx!.lineWidth = m.width; + ctx!.lineCap = "round"; + ctx!.beginPath(); + ctx!.moveTo(m.x, m.y); + ctx!.lineTo(tx, ty); + ctx!.stroke(); + const glow = ctx!.createRadialGradient(m.x, m.y, 0, m.x, m.y, 9); + glow.addColorStop(0, `rgba(255, 252, 240, ${0.9 * fade})`); + glow.addColorStop(0.4, `rgba(${r}, ${g}, ${b}, ${0.35 * fade})`); + glow.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`); + ctx!.fillStyle = glow; + ctx!.beginPath(); + ctx!.arc(m.x, m.y, 9, 0, Math.PI * 2); + ctx!.fill(); + } + + window.addEventListener("resize", resize); + resize(); + if (reduced) return () => window.removeEventListener("resize", resize); + + let next = 1.5; + let last = performance.now(); + let raf = 0; + const frame = (now: number) => { + // A hidden tab gets no frames; a long gap is not a burst of meteors. + const dt = Math.min((now - last) / 1000, 0.05); + last = now; + drawStars(now / 1000); + next -= dt; + if (next <= 0) { + spawn(); + next = EVERY * (0.5 + Math.random()); + } + for (let i = meteors.length - 1; i >= 0; i--) { + const m = meteors[i]; + m.life += dt; + m.x += m.dx * dt; + m.y += m.dy * dt; + if (m.life >= m.span) meteors.splice(i, 1); + else drawMeteor(m); + } + raf = requestAnimationFrame(frame); + }; + raf = requestAnimationFrame(frame); + return () => { + cancelAnimationFrame(raf); + window.removeEventListener("resize", resize); + }; + }, []); + + return