Spaces:
Running
Running
Replace with Gridiron Matrix
Browse files
service/web/src/components/app/Landing.tsx
CHANGED
|
@@ -1,13 +1,25 @@
|
|
| 1 |
-
import { useMemo } from "react"
|
| 2 |
import { Search } from "lucide-react"
|
| 3 |
import { Kbd, KbdGroup } from "@/components/ui/kbd"
|
| 4 |
import type { Player } from "@/lib/api"
|
| 5 |
import { OUTCOME } from "@/lib/colors"
|
| 6 |
|
| 7 |
export function Landing({ season, players, onSearch }: { season: number; players: Player[]; onSearch: () => void }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return (
|
| 9 |
-
<section
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
<div className="relative z-10 flex w-full max-w-2xl flex-1 flex-col items-center justify-center pb-[22vh] text-center">
|
| 12 |
<h1 className="text-5xl font-semibold tracking-tight sm:text-7xl">
|
| 13 |
Gridiron <span className="font-mono font-medium tracking-[0.08em] text-primary uppercase">Matrix</span>
|
|
@@ -71,7 +83,61 @@ function passes() {
|
|
| 71 |
return out
|
| 72 |
}
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
const geo = useMemo(() => {
|
| 76 |
const lines: { d: string; major: boolean }[] = []
|
| 77 |
for (let y = -10; y <= FAR; y += 5) if (y) lines.push({ d: path([[-HALF, y], [HALF, y]]), major: y % 10 === 0 })
|
|
@@ -96,11 +162,25 @@ function FieldBackdrop() {
|
|
| 96 |
}, [])
|
| 97 |
const top = project(0, FAR)[1] - 2
|
| 98 |
const bottom = project(0, NEAR)[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
return (
|
| 100 |
<div aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 -z-10 h-[72%]
|
| 101 |
[mask-image:linear-gradient(to_bottom,transparent,black_30%,black_85%,transparent)]">
|
| 102 |
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_50%_100%,rgba(16,185,129,0.12),transparent_65%)]" />
|
| 103 |
-
<svg viewBox={`-50 ${top} 100 ${bottom - top}`} preserveAspectRatio="xMidYMax slice" className="absolute inset-0 size-full text-foreground">
|
| 104 |
<path d={geo.turf} className="fill-foreground/[0.03]" />
|
| 105 |
{geo.lines.map((ln, i) => (
|
| 106 |
<path key={i} d={ln.d} stroke="currentColor" strokeOpacity={ln.major ? 0.13 : 0.06} strokeWidth={0.08} fill="none" />
|
|
@@ -108,11 +188,22 @@ function FieldBackdrop() {
|
|
| 108 |
{geo.hashes.map((d, i) => <path key={`h${i}`} d={d} stroke="currentColor" strokeOpacity={0.1} strokeWidth={0.07} />)}
|
| 109 |
{geo.sides.map((d, i) => <path key={`s${i}`} d={d} stroke="currentColor" strokeOpacity={0.18} strokeWidth={0.12} />)}
|
| 110 |
<path d={geo.los} stroke="#60a5fa" strokeOpacity={0.75} strokeWidth={0.16} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
{geo.throws.map((t, i) => {
|
| 112 |
const incomplete = t.type === "INCOMPLETE"
|
| 113 |
const color = incomplete ? "currentColor" : OUTCOME[t.type]
|
|
|
|
|
|
|
| 114 |
return (
|
| 115 |
-
<g key={i} className={incomplete ? "text-zinc-400 dark:text-zinc-300" : undefined}
|
|
|
|
|
|
|
| 116 |
<path d={t.arc} pathLength={1} fill="none" stroke="currentColor" strokeOpacity={0.35} strokeWidth={t.w * 0.6}
|
| 117 |
strokeLinecap="round" className="hero-throw text-foreground" style={{ animationDelay: `${t.delay}s` }} />
|
| 118 |
<g className="hero-ring" style={{ animationDelay: `${t.delay}s` }}>
|
|
@@ -124,6 +215,12 @@ function FieldBackdrop() {
|
|
| 124 |
)
|
| 125 |
})}
|
| 126 |
</svg>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
</div>
|
| 128 |
)
|
| 129 |
}
|
|
|
|
| 1 |
+
import { useEffect, useMemo, useRef, useState } from "react"
|
| 2 |
import { Search } from "lucide-react"
|
| 3 |
import { Kbd, KbdGroup } from "@/components/ui/kbd"
|
| 4 |
import type { Player } from "@/lib/api"
|
| 5 |
import { OUTCOME } from "@/lib/colors"
|
| 6 |
|
| 7 |
export function Landing({ season, players, onSearch }: { season: number; players: Player[]; onSearch: () => void }) {
|
| 8 |
+
// the cursor (or a dragging finger), in section coordinates - the dot matrix and the field both react to it
|
| 9 |
+
const cursor = useRef<{ x: number; y: number } | null>(null)
|
| 10 |
+
const [pointer, setPointer] = useState<{ cx: number; cy: number } | null>(null)
|
| 11 |
+
const sectionRef = useRef<HTMLElement>(null)
|
| 12 |
+
const move = (e: React.PointerEvent) => {
|
| 13 |
+
const r = sectionRef.current!.getBoundingClientRect()
|
| 14 |
+
cursor.current = { x: e.clientX - r.left, y: e.clientY - r.top }
|
| 15 |
+
setPointer({ cx: e.clientX, cy: e.clientY })
|
| 16 |
+
}
|
| 17 |
+
const leave = () => { cursor.current = null; setPointer(null) }
|
| 18 |
return (
|
| 19 |
+
<section ref={sectionRef} onPointerMove={move} onPointerDown={move} onPointerLeave={leave}
|
| 20 |
+
className="relative isolate flex min-h-[calc(100svh-3.5rem)] flex-col items-center overflow-hidden px-4">
|
| 21 |
+
<DotMatrix cursor={cursor} />
|
| 22 |
+
<FieldBackdrop pointer={pointer} />
|
| 23 |
<div className="relative z-10 flex w-full max-w-2xl flex-1 flex-col items-center justify-center pb-[22vh] text-center">
|
| 24 |
<h1 className="text-5xl font-semibold tracking-tight sm:text-7xl">
|
| 25 |
Gridiron <span className="font-mono font-medium tracking-[0.08em] text-primary uppercase">Matrix</span>
|
|
|
|
| 83 |
return out
|
| 84 |
}
|
| 85 |
|
| 86 |
+
// ---- the reactive dot matrix: a grid of dots that light up and lean away from the cursor, easing back after it ----
|
| 87 |
+
function DotMatrix({ cursor }: { cursor: React.RefObject<{ x: number; y: number } | null> }) {
|
| 88 |
+
const ref = useRef<HTMLCanvasElement>(null)
|
| 89 |
+
useEffect(() => {
|
| 90 |
+
const cv = ref.current!
|
| 91 |
+
const ctx = cv.getContext("2d")!
|
| 92 |
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
| 93 |
+
const GAP = 26, R = 170
|
| 94 |
+
let dots: { x: number; y: number; ox: number; oy: number; g: number }[] = []
|
| 95 |
+
let w = 0, h = 0, raf = 0
|
| 96 |
+
const resize = () => {
|
| 97 |
+
const dpr = Math.min(2, window.devicePixelRatio || 1)
|
| 98 |
+
w = cv.clientWidth; h = cv.clientHeight
|
| 99 |
+
cv.width = w * dpr; cv.height = h * dpr
|
| 100 |
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
| 101 |
+
dots = []
|
| 102 |
+
for (let y = GAP / 2; y < h; y += GAP) for (let x = GAP / 2; x < w; x += GAP) dots.push({ x, y, ox: 0, oy: 0, g: 0 })
|
| 103 |
+
}
|
| 104 |
+
resize()
|
| 105 |
+
const ro = new ResizeObserver(resize)
|
| 106 |
+
ro.observe(cv)
|
| 107 |
+
const frame = () => {
|
| 108 |
+
const c = cursor.current
|
| 109 |
+
const dark = document.documentElement.classList.contains("dark")
|
| 110 |
+
const base = dark ? "rgba(167,243,208," : "rgba(4,120,87,"
|
| 111 |
+
ctx.clearRect(0, 0, w, h)
|
| 112 |
+
const ease = reduced ? 1 : 0.14
|
| 113 |
+
for (const d of dots) {
|
| 114 |
+
let tx = 0, ty = 0, tg = 0
|
| 115 |
+
if (c) {
|
| 116 |
+
const dx = d.x - c.x, dy = d.y - c.y
|
| 117 |
+
const dist = Math.hypot(dx, dy)
|
| 118 |
+
if (dist < R) {
|
| 119 |
+
const k = 1 - dist / R
|
| 120 |
+
tg = k * k
|
| 121 |
+
if (!reduced && dist > 0.1) { tx = (dx / dist) * 9 * k; ty = (dy / dist) * 9 * k }
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
d.ox += (tx - d.ox) * ease; d.oy += (ty - d.oy) * ease; d.g += (tg - d.g) * ease
|
| 125 |
+
const a = 0.07 + 0.75 * d.g
|
| 126 |
+
ctx.fillStyle = base + a.toFixed(3) + ")"
|
| 127 |
+
ctx.beginPath()
|
| 128 |
+
ctx.arc(d.x + d.ox, d.y + d.oy, 0.9 + 1.3 * d.g, 0, Math.PI * 2)
|
| 129 |
+
ctx.fill()
|
| 130 |
+
}
|
| 131 |
+
raf = requestAnimationFrame(frame)
|
| 132 |
+
}
|
| 133 |
+
raf = requestAnimationFrame(frame)
|
| 134 |
+
return () => { cancelAnimationFrame(raf); ro.disconnect() }
|
| 135 |
+
}, [cursor])
|
| 136 |
+
return <canvas ref={ref} aria-hidden className="pointer-events-none absolute inset-0 -z-20 size-full" />
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
function FieldBackdrop({ pointer }: { pointer: { cx: number; cy: number } | null }) {
|
| 140 |
+
const svgRef = useRef<SVGSVGElement>(null)
|
| 141 |
const geo = useMemo(() => {
|
| 142 |
const lines: { d: string; major: boolean }[] = []
|
| 143 |
for (let y = -10; y <= FAR; y += 5) if (y) lines.push({ d: path([[-HALF, y], [HALF, y]]), major: y % 10 === 0 })
|
|
|
|
| 162 |
}, [])
|
| 163 |
const top = project(0, FAR)[1] - 2
|
| 164 |
const bottom = project(0, NEAR)[1]
|
| 165 |
+
// the cursor on the field: back through the camera to yards (x across, y past the LOS)
|
| 166 |
+
let at: { u: number; v: number; x: number; y: number } | null = null
|
| 167 |
+
const svg = svgRef.current
|
| 168 |
+
if (pointer && svg) {
|
| 169 |
+
const m = svg.getScreenCTM()
|
| 170 |
+
if (m) {
|
| 171 |
+
const p = new DOMPoint(pointer.cx, pointer.cy).matrixTransform(m.inverse())
|
| 172 |
+
if (p.y > 0) {
|
| 173 |
+
const d = (CAM_UP * FOCAL) / p.y
|
| 174 |
+
const y = d - CAM_BACK, x = (p.x * d) / FOCAL
|
| 175 |
+
if (y >= NEAR && y <= FAR && Math.abs(x) <= HALF) at = { u: p.x, v: p.y, x, y }
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
return (
|
| 180 |
<div aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 -z-10 h-[72%]
|
| 181 |
[mask-image:linear-gradient(to_bottom,transparent,black_30%,black_85%,transparent)]">
|
| 182 |
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_50%_100%,rgba(16,185,129,0.12),transparent_65%)]" />
|
| 183 |
+
<svg ref={svgRef} viewBox={`-50 ${top} 100 ${bottom - top}`} preserveAspectRatio="xMidYMax slice" className="absolute inset-0 size-full text-foreground">
|
| 184 |
<path d={geo.turf} className="fill-foreground/[0.03]" />
|
| 185 |
{geo.lines.map((ln, i) => (
|
| 186 |
<path key={i} d={ln.d} stroke="currentColor" strokeOpacity={ln.major ? 0.13 : 0.06} strokeWidth={0.08} fill="none" />
|
|
|
|
| 188 |
{geo.hashes.map((d, i) => <path key={`h${i}`} d={d} stroke="currentColor" strokeOpacity={0.1} strokeWidth={0.07} />)}
|
| 189 |
{geo.sides.map((d, i) => <path key={`s${i}`} d={d} stroke="currentColor" strokeOpacity={0.18} strokeWidth={0.12} />)}
|
| 190 |
<path d={geo.los} stroke="#60a5fa" strokeOpacity={0.75} strokeWidth={0.16} />
|
| 191 |
+
{at && (
|
| 192 |
+
<g className="text-primary" pointerEvents="none">
|
| 193 |
+
<path d={path([[-HALF, at.y], [HALF, at.y]])} stroke="currentColor" strokeOpacity={0.45} strokeWidth={0.07} strokeDasharray="0.4 0.4" />
|
| 194 |
+
<path d={path([[at.x, NEAR], [at.x, FAR]])} stroke="currentColor" strokeOpacity={0.45} strokeWidth={0.07} strokeDasharray="0.4 0.4" />
|
| 195 |
+
<circle cx={at.u} cy={at.v} r={0.35} fill="currentColor" />
|
| 196 |
+
</g>
|
| 197 |
+
)}
|
| 198 |
{geo.throws.map((t, i) => {
|
| 199 |
const incomplete = t.type === "INCOMPLETE"
|
| 200 |
const color = incomplete ? "currentColor" : OUTCOME[t.type]
|
| 201 |
+
const near = at ? Math.hypot(t.x - at.x, t.y - at.y) : 99
|
| 202 |
+
const lift = near < 7 ? 1 + 0.9 * (1 - near / 7) : 1
|
| 203 |
return (
|
| 204 |
+
<g key={i} className={incomplete ? "text-zinc-400 dark:text-zinc-300" : undefined}
|
| 205 |
+
style={{ transform: `scale(${lift})`, transformOrigin: `${t.u}px ${t.v}px`, transformBox: "view-box",
|
| 206 |
+
transition: "transform 180ms ease-out", filter: lift > 1.05 ? `drop-shadow(0 0 ${(lift - 1) * 1.2}px ${incomplete ? "#e4e4e7" : color})` : undefined }}>
|
| 207 |
<path d={t.arc} pathLength={1} fill="none" stroke="currentColor" strokeOpacity={0.35} strokeWidth={t.w * 0.6}
|
| 208 |
strokeLinecap="round" className="hero-throw text-foreground" style={{ animationDelay: `${t.delay}s` }} />
|
| 209 |
<g className="hero-ring" style={{ animationDelay: `${t.delay}s` }}>
|
|
|
|
| 215 |
)
|
| 216 |
})}
|
| 217 |
</svg>
|
| 218 |
+
{at && pointer && (
|
| 219 |
+
<div className="lab-label pointer-events-none fixed z-20 rounded-sm border border-primary/30 bg-background/80 px-1.5 py-0.5 text-primary backdrop-blur-sm"
|
| 220 |
+
style={{ left: pointer.cx + 14, top: pointer.cy + 14 }}>
|
| 221 |
+
{at.y >= 0 ? `+${at.y.toFixed(0)} yd` : `${at.y.toFixed(0)} yd`} · {Math.abs(at.x) < 0.5 ? "middle" : `${Math.abs(at.x).toFixed(1)} yd ${at.x < 0 ? "L" : "R"}`}
|
| 222 |
+
</div>
|
| 223 |
+
)}
|
| 224 |
</div>
|
| 225 |
)
|
| 226 |
}
|