{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"topographic-contour-waves-canvas-background","type":"registry:block","title":"Topographic Contour Waves","description":"","dependencies":[],"files":[{"path":"components/we-inc/topographic-contour-waves-canvas-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// A survey map that breathes: the height field under the paper is five drifting hills and hollows\n// plus a long swell, and its contour lines are traced every frame with marching squares.\n// Change these: ink colour, contour gap (in field units), cell size (smaller is smoother, costlier), speed.\nconst INK = \"59,58,54\"; // rgb of the lines\nconst ACCENT = \"178,85,46\"; // one rust contour\nconst STEP = 0.06;\nconst CELL = 14;\nconst SPEED = 0.1;\n// [x, y, radius, height, phase] as fractions of the box; negative height is a hollow\nconst HILLS = [[0.74, 0.4, 0.3, 1, 0], [0.32, 0.86, 0.26, 0.8, 1.7], [0.98, 0.95, 0.2, 0.7, 3.1], [0.5, 0.15, 0.22, -0.6, 4.4], [0.08, 0.35, 0.2, -0.5, 2.2]];\n// Which cell edges (0 top, 1 right, 2 bottom, 3 left) each of the 16 corner cases joins.\nconst SEGMENTS = [[], [[3, 2]], [[2, 1]], [[3, 1]], [[0, 1]], [[3, 0], [2, 1]], [[0, 2]], [[3, 0]], [[3, 0]], [[0, 2]], [[0, 1], [3, 2]], [[0, 1]], [[3, 1]], [[2, 1]], [[3, 2]], []];\n\nexport default function TopographicContourWaves() {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let onScreen = true;\n    const born = performance.now();\n    const cleanups: (() => void)[] = [];\n    let field = new Float32Array(0);\n    const draw = (t: number) => {\n      ctx.clearRect(0, 0, w, h);\n      const cols = Math.ceil(w / CELL) + 2;\n      const rows = Math.ceil(h / CELL) + 2;\n      if (field.length !== cols * rows) field = new Float32Array(cols * rows);\n      const m = Math.max(w, h * 1.4);\n      const hills = HILLS.map(([hx, hy, hr, hh, ph]) => [\n        w * (hx + 0.06 * Math.sin(t * SPEED + ph)),\n        h * (hy + 0.08 * Math.cos(t * SPEED * 0.8 + ph * 1.3)),\n        1 / Math.pow(m * hr * (1 + 0.15 * Math.sin(t * SPEED * 1.3 + ph)), 2),\n        hh,\n      ]);\n      for (let j = 0; j < rows; j++) {\n        const y = (j - 1) * CELL;\n        for (let i = 0; i < cols; i++) {\n          const x = (i - 1) * CELL;\n          let v = 0.22 * Math.sin(x * 0.005 + t * SPEED * 0.9) * Math.cos(y * 0.007 - t * SPEED * 0.6);\n          for (const [cx, cy, inv, hh] of hills) v += hh * Math.exp(-((x - cx) * (x - cx) + (y - cy) * (y - cy)) * inv);\n          field[j * cols + i] = v;\n        }\n      }\n      const pt = [0, 0, 0, 0, 0, 0, 0, 0];\n      for (let level = -16; level <= 20; level++) {\n        const v = level * STEP + 0.01;\n        ctx.beginPath();\n        for (let j = 0; j < rows - 1; j++) {\n          for (let i = 0; i < cols - 1; i++) {\n            const a = field[j * cols + i];\n            const b = field[j * cols + i + 1];\n            const c = field[(j + 1) * cols + i + 1];\n            const d = field[(j + 1) * cols + i];\n            const k = (a > v ? 8 : 0) | (b > v ? 4 : 0) | (c > v ? 2 : 0) | (d > v ? 1 : 0);\n            if (k === 0 || k === 15) continue;\n            const x0 = (i - 1) * CELL;\n            const y0 = (j - 1) * CELL;\n            pt[0] = x0 + (CELL * (v - a)) / (b - a); pt[1] = y0;\n            pt[2] = x0 + CELL; pt[3] = y0 + (CELL * (v - b)) / (c - b);\n            pt[4] = x0 + (CELL * (v - d)) / (c - d); pt[5] = y0 + CELL;\n            pt[6] = x0; pt[7] = y0 + (CELL * (v - a)) / (d - a);\n            for (const [e1, e2] of SEGMENTS[k]) {\n              ctx.moveTo(pt[e1 * 2], pt[e1 * 2 + 1]);\n              ctx.lineTo(pt[e2 * 2], pt[e2 * 2 + 1]);\n            }\n          }\n        }\n        const rust = level === 9;\n        const index = level % 5 === 0;\n        ctx.strokeStyle = rust ? \"rgba(\" + ACCENT + \",.7)\" : \"rgba(\" + INK + \",\" + (index ? 0.5 : 0.24) + \")\";\n        ctx.lineWidth = rust ? 1.4 : index ? 1.15 : 0.75;\n        ctx.stroke();\n      }\n    };\n    const now = () => 14 + (performance.now() - born) / 1000;\n    const frame = () => {\n      raf = 0;\n      draw(now());\n      if (onScreen && !reduce) raf = requestAnimationFrame(frame);\n    };\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      w = r.width;\n      h = r.height;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      draw(reduce ? 14 : now());\n    };\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    resize();\n    const io = new IntersectionObserver((entries) => {\n      onScreen = entries[0].isIntersecting;\n      if (onScreen && !reduce && !raf) raf = requestAnimationFrame(frame);\n    });\n    io.observe(canvas);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      cleanups.forEach((c) => c());\n    };\n  }, []);\n  return (\n    <section className=\"relative isolate min-h-[640px] overflow-hidden bg-[#efe8dc]\">\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        <div className=\"absolute inset-0 [background-image:linear-gradient(rgba(59,58,54,.05)_1px,transparent_1px),linear-gradient(90deg,rgba(59,58,54,.05)_1px,transparent_1px)] [background-size:120px_120px]\" />\n        <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <div className=\"absolute inset-0 [background:radial-gradient(55%_60%_at_22%_38%,rgba(239,232,220,.92),rgba(239,232,220,.55)_55%,transparent)]\" />\n      </div>\n      <div className=\"mx-auto max-w-5xl px-6 py-24 sm:py-32\">\n        <p className=\"text-sm font-semibold uppercase tracking-[0.16em] text-[#8a3f20]\">Ridgeway Survey Co.</p>\n        <h1 className=\"mt-4 max-w-xl text-4xl font-semibold leading-[1.08] tracking-tight text-[#24221e] sm:text-6xl\">Land surveys drawn to the centimetre.</h1>\n        <p className=\"mt-5 max-w-lg text-lg leading-relaxed text-[#4a463e]\">Boundary, topographic and measured building surveys for architects, farms and self-builders.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-sm bg-[#24221e] px-7 text-sm font-semibold text-[#f3ede2] transition hover:bg-[#3d3a33] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#24221e] focus-visible:ring-offset-2 focus-visible:ring-offset-[#efe8dc]\">Ask for a quote</a>\n      </div>\n    </section>\n  );\n}\n"}]}
