{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"wind-map-flow-field-background-with-fine-streaks-spiralling-into-a-low","type":"registry:block","title":"Wind Map Flow Field","description":"Free animated wind map background: fine streaks ride a flow field and spiral into a low-pressure system. React and plain HTML versions, canvas 2D, no libraries.","dependencies":[],"files":[{"path":"components/we-inc/wind-map-flow-field-background-with-fine-streaks-spiralling-into-a-low.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// The values worth changing.\nconst SETTINGS = {\n  density: 520, // square pixels per streak; lower draws more wind\n  speed: 1, // how fast the air moves; 0.6 is a calm day\n  trail: 0.075, // how quickly old strokes fade; higher gives shorter streaks\n  calm: \"rgba(118, 152, 178, 0.55)\", // slow air\n  breeze: \"rgba(196, 216, 228, 0.7)\", // middling air\n  gust: \"rgba(255, 226, 184, 0.9)\", // the fastest air, near the low\n};\n\n// The wind: a slow rolling field plus one low-pressure system that air spirals into.\nfunction windAngle(x: any, y: any, t: any, w: any, h: any) {\n  const base = Math.sin(x * 0.0019 + t * 0.045) * 1.5 + Math.cos(y * 0.0026 - t * 0.035) * 1.3 + Math.sin((x + y) * 0.0011 + 1.3);\n  const cx = w * (w < 700 ? 0.6 : 0.72) + Math.sin(t * 0.05) * 40;\n  const cy = h * (w < 700 ? 0.8 : 0.5) + Math.cos(t * 0.04) * 30;\n  const dx = x - cx;\n  const dy = y - cy;\n  const d = Math.sqrt(dx * dx + dy * dy) + 1;\n  const spin = Math.atan2(dy, dx) + Math.PI / 2 + 0.35;\n  const k = Math.exp(-d / (Math.min(w, h) * 0.42));\n  // Blend directions as vectors, not angles, so there is no seam where the angle wraps around.\n  const vx = Math.cos(base) * (1 - k) + Math.cos(spin) * k;\n  const vy = Math.sin(base) * (1 - k) + Math.sin(spin) * k;\n  return { a: Math.atan2(vy, vx), s: 0.55 + 0.25 * Math.sin(x * 0.004 + y * 0.003 + t * 0.2) + k * 1.4 };\n}\n\nconst SCENE: any = {\n  start: 0,\n  still: 0,\n  init(ctx: any, w: any, h: any) {\n    const n = Math.round((w * h) / SETTINGS.density);\n    const ps: any[] = [];\n    for (let i = 0; i < n; i++) ps.push({ x: Math.random() * w, y: Math.random() * h, life: Math.random() * 160 });\n    const st = { ps, t: 0 };\n    ctx.clearRect(0, 0, w, h);\n    // Run the wind for a while first so the very first frame is already full of streaks.\n    for (let i = 0; i < 70; i++) SCENE.step(ctx, w, h, st, 1 / 60);\n    return st;\n  },\n  step(ctx: any, w: any, h: any, st: any, dt: any) {\n    st.t += dt;\n    ctx.globalCompositeOperation = \"destination-out\";\n    ctx.fillStyle = `rgba(0,0,0,${SETTINGS.trail})`;\n    ctx.fillRect(0, 0, w, h);\n    ctx.globalCompositeOperation = \"source-over\";\n    const paths = [new Path2D(), new Path2D(), new Path2D()];\n    const move = SETTINGS.speed * dt * 60 * 1.6;\n    for (const p of st.ps) {\n      const f = windAngle(p.x, p.y, st.t, w, h);\n      const nx = p.x + Math.cos(f.a) * f.s * move;\n      const ny = p.y + Math.sin(f.a) * f.s * move;\n      const bucket = f.s < 0.6 ? 0 : f.s < 1 ? 1 : 2;\n      paths[bucket].moveTo(p.x, p.y);\n      paths[bucket].lineTo(nx, ny);\n      p.x = nx;\n      p.y = ny;\n      p.life -= dt * 60;\n      if (p.life < 0 || p.x < -10 || p.x > w + 10 || p.y < -10 || p.y > h + 10) {\n        p.x = Math.random() * w;\n        p.y = Math.random() * h;\n        p.life = 80 + Math.random() * 160;\n      }\n    }\n    ctx.lineWidth = 1;\n    ctx.lineCap = \"round\";\n    const colours = [SETTINGS.calm, SETTINGS.breeze, SETTINGS.gust];\n    for (let i = 0; i < 3; i++) {\n      ctx.strokeStyle = colours[i];\n      ctx.stroke(paths[i]);\n    }\n  },\n  draw(ctx: any, w: any, h: any, t: any, st: any, ptr: any, dt: any) {\n    if (dt > 0) SCENE.step(ctx, w, h, st, dt);\n  },\n};\n\n// Runs a scene on a canvas: sizes it to the block, pauses off screen and in hidden tabs, cleans up after itself.\nfunction runScene(root: any, canvas: any, scene: any, reduced: boolean) {\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return () => {};\n  let w = 0;\n  let h = 0;\n  let st: any = null;\n  let raf = 0;\n  let last = 0;\n  let acc = 0;\n  let onScreen = true;\n  let time = reduced ? (scene.still ?? scene.start ?? 0) : (scene.start ?? 0);\n  const ptr: any = { x: 0, y: 0, on: false, down: 0 };\n  const step = 1 / (scene.fps || 60);\n  const resize = () => {\n    const r = root.getBoundingClientRect();\n    const nw = Math.max(1, Math.round(r.width));\n    const nh = Math.max(1, Math.round(r.height));\n    if (nw === w && nh === h && st) return;\n    w = nw;\n    h = nh;\n    // Device pixels are capped at 1.5 and scaled by the scene's own quality factor.\n    const d = Math.min(window.devicePixelRatio || 1, 1.5) * (scene.scale || 1);\n    canvas.width = Math.max(1, Math.round(w * d));\n    canvas.height = Math.max(1, Math.round(h * d));\n    ctx.setTransform(canvas.width / w, 0, 0, canvas.height / h, 0, 0);\n    st = scene.init(ctx, w, h, canvas.width / w);\n    scene.draw(ctx, w, h, time, st, ptr, 0);\n  };\n  const tick = (now: number) => {\n    raf = requestAnimationFrame(tick);\n    const dt = last ? Math.min(0.1, (now - last) / 1000) : step;\n    last = now;\n    acc += dt;\n    if (acc < step * 0.95) return;\n    const used = Math.min(acc, 0.1);\n    acc = 0;\n    time += used;\n    scene.draw(ctx, w, h, time, st, ptr, used);\n  };\n  const play = () => {\n    if (raf || reduced || !onScreen || document.hidden) return;\n    last = 0;\n    raf = requestAnimationFrame(tick);\n  };\n  const stop = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(root);\n  const io = new IntersectionObserver((entries: any) => {\n    onScreen = entries[0].isIntersecting;\n    if (onScreen) play();\n    else stop();\n  });\n  io.observe(root);\n  const onVis = () => (document.hidden ? stop() : play());\n  const onMove = (e: any) => {\n    const r = root.getBoundingClientRect();\n    ptr.x = e.clientX - r.left;\n    ptr.y = e.clientY - r.top;\n    ptr.on = true;\n  };\n  const onLeave = () => {\n    ptr.on = false;\n  };\n  const onDown = (e: any) => {\n    onMove(e);\n    ptr.down += 1;\n  };\n  document.addEventListener(\"visibilitychange\", onVis);\n  root.addEventListener(\"pointermove\", onMove);\n  root.addEventListener(\"pointerleave\", onLeave);\n  root.addEventListener(\"pointerdown\", onDown);\n  resize();\n  play();\n  return () => {\n    stop();\n    ro.disconnect();\n    io.disconnect();\n    document.removeEventListener(\"visibilitychange\", onVis);\n    root.removeEventListener(\"pointermove\", onMove);\n    root.removeEventListener(\"pointerleave\", onLeave);\n    root.removeEventListener(\"pointerdown\", onDown);\n  };\n}\n\nexport default function WindMapFlowFieldBackground() {\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    // Visitors who prefer reduced motion get one settled frame and no loop.\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    return runScene(root, canvas, SCENE, reduced);\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative h-[640px] w-full overflow-hidden bg-[#0c1520] text-[#f2f5f7]\" style={{ backgroundImage: \"linear-gradient(rgba(140,170,200,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(140,170,200,.06) 1px, transparent 1px)\", backgroundSize: \"72px 72px\" }}>\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 block h-full w-full\" />\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"linear-gradient(90deg, rgba(12,21,32,.92) 0%, rgba(12,21,32,.7) 38%, rgba(12,21,32,0) 70%)\" }} />\n      <div className=\"relative z-10 mx-auto flex h-full max-w-6xl flex-col justify-center items-start text-left px-6 py-14 sm:px-10\">\n        <div className=\"max-w-xl\">\n          <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#f3d9b1]\">Fairlead marine forecasts</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl lg:text-6xl\">Know the wind before you leave the mooring.</h2>\n          <p className=\"mt-5 text-base leading-relaxed text-[#c3ced8] sm:text-lg\">Hour by hour wind, gusts and swell for the anchorages you actually sail, checked by forecasters who live on the coast.</p>\n          <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-[6px] bg-[#f3d9b1] px-6 text-sm font-semibold text-[#1a1410] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f3d9b1] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0c1520]\">See this week’s forecast</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
