// Animated SVG compass rose. const CX = 96, CY = 96, R = 80 const CARDINALS = [ { label: 'N', angle: 0 }, { label: 'E', angle: 90 }, { label: 'S', angle: 180 }, { label: 'W', angle: 270 }, ] function polarXY(cx, cy, r, angleDeg) { const rad = (angleDeg - 90) * Math.PI / 180 return { x: cx + r * Math.cos(rad), y: cy + r * Math.sin(rad) } } export default function Compass({ heading = 0, cog }) { const hdg = heading ?? 0 const hasCog = cog != null return ( {/* Outer ring */} {/* Rotating rose */} {/* 36 tick marks */} {Array.from({ length: 36 }, (_, i) => { const angle = i * 10 const outer = polarXY(CX, CY, R, angle) const inner = polarXY(CX, CY, R - (i % 3 === 0 ? 10 : 5), angle) return ( ) })} {/* Cardinal labels */} {CARDINALS.map(c => { const p = polarXY(CX, CY, R - 22, c.angle) return ( {c.label} ) })} {/* Fixed lubber line (ship's bow = top) */} {/* COG indicator */} {hasCog && (() => { const cogAngle = cog - hdg const tip = polarXY(CX, CY, R - 6, cogAngle) return ( ) })()} {/* Center */} {/* Heading value */} {Math.round(hdg).toString().padStart(3, '0')}° HEADING ) }