From 00fc2adf638a21bb7246669f72381244f24b620c Mon Sep 17 00:00:00 2001 From: anonymousratwastaken Date: Sat, 24 Oct 2026 09:51:47 +0100 Subject: [PATCH] added a funky background to the donate page --- src/app/donate/page.tsx | 4 +- src/components/wave-pattern.tsx | 112 ++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/components/wave-pattern.tsx diff --git a/src/app/donate/page.tsx b/src/app/donate/page.tsx index 0bcf851..ab1b98c 100644 --- a/src/app/donate/page.tsx +++ b/src/app/donate/page.tsx @@ -15,6 +15,7 @@ import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { TIERS, tierForAmount, upgradePrice } from "@/lib/donations"; import { TopBar } from "@/components/top-bar"; +import WaveBackground from "@/components/wave-pattern"; const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY ?? ""); @@ -540,7 +541,8 @@ export default function DonatePage() { if (!started) { return ( -
+
+
diff --git a/src/components/wave-pattern.tsx b/src/components/wave-pattern.tsx new file mode 100644 index 0000000..dd8f8c6 --- /dev/null +++ b/src/components/wave-pattern.tsx @@ -0,0 +1,112 @@ +"use client" +import { useEffect, useRef } from "react" +import { cn } from "@/lib/utils" + +export default function GridBackground({ className }: { className?: string }) { + const canvasRef = useRef(null) + + useEffect(() => { + const canvas = canvasRef.current + if (!canvas) return + const ctx = canvas.getContext("2d") + if (!ctx) return + + let animationId: number + let width = 0 + let height = 0 + + const PIXEL_SIZE = 6 + const WAVE_SPEED = 0.012 + const WAVE_AMP = 0.10 + const WAVE_FREQ = 2.8 + const FALLOFF = 0.35 // how far upward the glow reaches + + const resize = () => { + const dpr = window.devicePixelRatio || 1 + width = window.innerWidth + height = window.innerHeight + canvas.width = width * dpr + canvas.height = height * dpr + ctx.setTransform(dpr, 0, 0, dpr, 0, 0) + } + + resize() + + let t = 0 + + const bayer4x4 = [ + [0.0, 0.5, 0.125, 0.625], + [0.75, 0.25, 0.875, 0.375], + [0.1875, 0.6875, 0.0625, 0.5625], + [0.9375, 0.4375, 0.8125, 0.3125] + ] + + const draw = () => { + ctx.clearRect(0, 0, width, height) + + // Prioritize the 'dark' class set by next-themes to avoid system overrides + const isDark = document.documentElement.classList.contains("dark") + // Use the theme's primary colour (falls back to foreground) + const cs = getComputedStyle(document.documentElement) + const primary = cs.getPropertyValue("--primary").trim() || cs.getPropertyValue("--foreground").trim() + const alpha = isDark ? 0.18 : 0.14 + + const cols = Math.ceil(width / PIXEL_SIZE) + 1 + const rows = Math.ceil(height / PIXEL_SIZE) + 1 + // Falloff reaches upward from the wave + const falloffPx = FALLOFF * height + const amp = WAVE_AMP * height + + // color-mix applies the alpha since --primary may be any CSS colour format + ctx.fillStyle = `color-mix(in oklab, ${primary} ${alpha * 100}%, transparent)` + + for (let row = 0; row <= rows; row++) { + for (let col = 0; col <= cols; col++) { + const x = col * PIXEL_SIZE + const y = row * PIXEL_SIZE + + const wx = (x / width) * Math.PI * 2 * WAVE_FREQ + // Move the wave lower (75% down the screen) + const waveY = (height * 0.90) - amp * Math.sin(wx + t) + + // dist: 0 = at or below the wave, positive = above wave + const dist = Math.max(0, waveY - y) + + // intensity: 1 = at wave line, 0 = far above it + let intensity = Math.max(0, 1 - dist / falloffPx) + intensity = intensity * intensity + + // Dither check: below waveY is always intensity 1, so it draws solid + if (intensity <= bayer4x4[row % 4][col % 4]) continue + + ctx.fillRect(x, y, PIXEL_SIZE, PIXEL_SIZE) + } + } + + t += WAVE_SPEED + animationId = requestAnimationFrame(draw) + } + + draw() + + const onResize = () => { + ctx.resetTransform() + resize() + } + window.addEventListener("resize", onResize) + + return () => { + cancelAnimationFrame(animationId) + window.removeEventListener("resize", onResize) + } + }, []) + + return ( +