{
  "id": "connected-vertices-canvas",
  "kind": "element",
  "title": "Connected vertices canvas",
  "summary": "Drifting points joined by lines when they are near each other, with brighter links to the pointer.",
  "url": "https://enrichr.dev/elements/connected-vertices-canvas.html",
  "section": "background",
  "techniques": [
    "pointer-interaction"
  ],
  "stack": [
    "Vanilla JS",
    "Canvas"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "technical",
    "calm"
  ],
  "intents": [
    "particle network background",
    "connected dots canvas",
    "constellation lines effect",
    "nodes and links background",
    "interactive particles hero"
  ],
  "status": "tested",
  "params": [
    {
      "key": "density",
      "label": "Density (points per 10,000 px squared)",
      "type": "range",
      "min": 0.3,
      "max": 5,
      "step": 0.1,
      "value": 1.8
    },
    {
      "key": "linkDistance",
      "label": "Link distance (px)",
      "type": "range",
      "min": 40,
      "max": 220,
      "step": 5,
      "value": 110
    },
    {
      "key": "speed",
      "label": "Drift speed",
      "type": "range",
      "min": 0,
      "max": 3,
      "step": 0.1,
      "value": 1
    },
    {
      "key": "colorA",
      "label": "Points and links",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "colorB",
      "label": "Pointer links",
      "type": "color",
      "value": "#fbf8f1"
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Connected vertices canvas\" element to this project.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/connected-vertices-canvas.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Connected vertices canvas\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Connected vertices canvas\" element to this codebase.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-connected-vertices-canvas.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Connected vertices canvas element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Connected vertices canvas\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- connected-vertices-canvas.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./connected-vertices-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ConnectedVerticesCanvas(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Connected vertices canvas\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- connected-vertices-canvas.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/ConnectedVerticesCanvas.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./connected-vertices-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ConnectedVerticesCanvas(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Connected vertices canvas\" element.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), connected-vertices-canvas.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Connected vertices canvas\" element. No packages, no server code.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load connected-vertices-canvas.js and then main.js), style.css (the CSS below), connected-vertices-canvas.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Connected vertices canvas\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nWhat it does: Points drift with a small velocity and bounce off the edges. To find pairs that are close enough to join, the canvas is split into a grid whose cells are as wide as the link distance, so each point only checks its own cell and the eight around it instead of every other point. Links are collected into five paths by strength and stroked once per path, which keeps the number of draw calls fixed. The pointer joins any point within a larger radius and gently pulls nearby points toward it.\nAccessibility: The canvas is decorative and has a text label. Reduced motion freezes the points where they are, and the pointer links still appear on movement without anything drifting. Nothing here needs keyboard input.\n\nTunable settings:\n- Density (points per 10,000 px squared): range 0.3 to 5, step 0.1, default 1.8\n- Link distance (px): range 40 to 220, step 5, default 110\n- Drift speed: range 0 to 3, step 0.1, default 1\n- Points and links: color, default #e6ff55\n- Pointer links: color, default #fbf8f1\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/connected-vertices-canvas.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Connected vertices canvas\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it ConnectedVerticesCanvas.\n2. Paste the JavaScript below into a separate code file named connected-vertices-canvas.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./connected-vertices-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ConnectedVerticesCanvas(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(ConnectedVerticesCanvas, {\n  density: { type: ControlType.Number, title: \"Density\", min: 0.3, max: 5, step: 0.1, defaultValue: 1.8 },\n  linkDistance: { type: ControlType.Number, title: \"Link distance\", min: 40, max: 220, step: 5, defaultValue: 110 },\n  speed: { type: ControlType.Number, title: \"Drift speed\", min: 0, max: 3, step: 0.1, defaultValue: 1 },\n  colorA: { type: ControlType.Color, title: \"Points and links\", defaultValue: \"#e6ff55\" },\n  colorB: { type: ControlType.Color, title: \"Pointer links\", defaultValue: \"#fbf8f1\" },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Connected vertices canvas\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Connected vertices canvas\" element from the Enrichr Library: Drifting points joined by lines when they are near each other, with brighter links to the pointer.\nPage: https://enrichr.dev/elements/connected-vertices-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/connected-vertices-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-connected-vertices-canvas\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-connected-vertices-canvas\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "The canvas is decorative and has a text label. Reduced motion freezes the points where they are, and the pointer links still appear on movement without anything drifting. Nothing here needs keyboard input.",
  "performance": "The grid makes neighbour search roughly linear in the number of points, and drawing is five line paths plus the dots. Point count is capped at 900 and the loop pauses off screen or in a hidden tab.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-cv\"><canvas class=\"ef-cv__c\" role=\"img\" aria-label=\"Drifting points joined by thin lines when they are close to each other or to the pointer\"></canvas></div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-cv { position: relative; width: 100%; min-height: 20rem; overflow: hidden; border-radius: 1rem; background: radial-gradient(ellipse at 50% 35%, #12382c, #0c1e18 70%); touch-action: pan-y; cursor: crosshair; }\n.ef-cv__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Connected vertices canvas: drifting points joined by lines whenever two are close enough, and by brighter lines to the pointer. A uniform grid (spatial hash) keeps neighbour lookups cheap.\n// Reduced motion freezes the points in place (the pointer still lights up nearby links). The loop pauses when the element is off screen.\n// mount(root, { density (points per 10,000 square px), linkDistance (px), speed (0-3), colorA (points and links), colorB (pointer links) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-cv\");\n  var canvas = root.querySelector(\".ef-cv__c\");\n  var ctx = canvas.getContext(\"2d\");\n  var opts = {}, raf = 0, visible = true, io = null, ro = null, destroyed = false, last = 0;\n  var W = 1, H = 1, dpr = 1, n = 0, px, py, vx, vy, sz;\n  var cols = 1, rows = 1, cell = 100, head = new Int32Array(1), next = new Int32Array(1);\n  var mx = -9999, my = -9999, hasPtr = false, ca = [230, 255, 85], cb = [251, 248, 241], seed = 4217;\n  var BUCKETS = 5;\n\n  function rnd() { seed = (seed * 1664525 + 1013904223) >>> 0; return seed / 4294967296; }\n  function rgb(h, d) { var m = /^#?([0-9a-f]{6})$/i.exec(h || \"\"); var v = parseInt(m ? m[1] : d, 16); return [v >> 16, (v >> 8) & 255, v & 255]; }\n  function rgba(c, a) { return \"rgba(\" + c[0] + \",\" + c[1] + \",\" + c[2] + \",\" + a + \")\"; }\n\n  function populate() {\n    var want = Math.max(24, Math.min(900, Math.round(opts.density * W * H / 10000)));\n    if (want === n && px) return;\n    var ox = px, oy = py, ovx = vx, ovy = vy, osz = sz, on = n;\n    px = new Float32Array(want); py = new Float32Array(want); vx = new Float32Array(want); vy = new Float32Array(want); sz = new Float32Array(want);\n    for (var i = 0; i < want; i++) {\n      if (i < on) { px[i] = ox[i]; py[i] = oy[i]; vx[i] = ovx[i]; vy[i] = ovy[i]; sz[i] = osz[i]; }\n      else {\n        var a = rnd() * 6.2832, s = 14 + rnd() * 26;\n        px[i] = rnd() * W; py[i] = rnd() * H; vx[i] = Math.cos(a) * s; vy[i] = Math.sin(a) * s; sz[i] = 1 + rnd() * 1.6;\n      }\n    }\n    n = want; next = new Int32Array(n);\n  }\n  function size() {\n    dpr = Math.min(window.devicePixelRatio || 1, 2);\n    W = Math.max(1, wrap.clientWidth); H = Math.max(1, wrap.clientHeight);\n    canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr);\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    for (var i = 0; i < n; i++) { if (px[i] > W) px[i] = rnd() * W; if (py[i] > H) py[i] = rnd() * H; }\n    populate();\n  }\n  function grid() {\n    cell = Math.max(24, opts.linkDistance);\n    cols = Math.max(1, Math.ceil(W / cell)); rows = Math.max(1, Math.ceil(H / cell));\n    if (head.length !== cols * rows) head = new Int32Array(cols * rows);\n    head.fill(-1);\n    for (var i = 0; i < n; i++) {\n      var cx = Math.min(cols - 1, Math.max(0, (px[i] / cell) | 0)), cy = Math.min(rows - 1, Math.max(0, (py[i] / cell) | 0));\n      var k = cy * cols + cx; next[i] = head[k]; head[k] = i;\n    }\n  }\n  function step(dt) {\n    var sp = opts.speed, pr = opts.linkDistance * 1.7, pr2 = pr * pr;\n    for (var i = 0; i < n; i++) {\n      var x = px[i], y = py[i];\n      if (hasPtr) {\n        var dx = mx - x, dy = my - y, d2 = dx * dx + dy * dy;\n        if (d2 < pr2 && d2 > 1) { var d = Math.sqrt(d2), pull = (1 - d / pr) * 38 * dt; vx[i] += dx / d * pull; vy[i] += dy / d * pull; }\n      }\n      var s2 = vx[i] * vx[i] + vy[i] * vy[i];\n      if (s2 > 3600) { var k = 60 / Math.sqrt(s2); vx[i] *= k; vy[i] *= k; }\n      else if (s2 < 100) { vx[i] *= 1.02; vy[i] *= 1.02; }\n      x += vx[i] * sp * dt; y += vy[i] * sp * dt;\n      if (x < 0) { x = 0; vx[i] = Math.abs(vx[i]); } else if (x > W) { x = W; vx[i] = -Math.abs(vx[i]); }\n      if (y < 0) { y = 0; vy[i] = Math.abs(vy[i]); } else if (y > H) { y = H; vy[i] = -Math.abs(vy[i]); }\n      px[i] = x; py[i] = y;\n    }\n  }\n  function render() {\n    ctx.clearRect(0, 0, W, H);\n    grid();\n    var L = opts.linkDistance, L2 = L * L, b, i, j, k, cx, cy, ox, oy, nx, ny, dx, dy, d2;\n    // bucket link segments by strength so we stroke a handful of paths, not thousands\n    var paths = [];\n    for (b = 0; b < BUCKETS; b++) paths.push(new Path2D());\n    for (i = 0; i < n; i++) {\n      cx = Math.min(cols - 1, Math.max(0, (px[i] / cell) | 0)); cy = Math.min(rows - 1, Math.max(0, (py[i] / cell) | 0));\n      for (oy = -1; oy <= 1; oy++) {\n        ny = cy + oy; if (ny < 0 || ny >= rows) continue;\n        for (ox = -1; ox <= 1; ox++) {\n          nx = cx + ox; if (nx < 0 || nx >= cols) continue;\n          for (j = head[ny * cols + nx]; j !== -1; j = next[j]) {\n            if (j <= i) continue;\n            dx = px[i] - px[j]; dy = py[i] - py[j]; d2 = dx * dx + dy * dy;\n            if (d2 < L2) {\n              b = Math.min(BUCKETS - 1, ((1 - Math.sqrt(d2) / L) * BUCKETS) | 0);\n              paths[b].moveTo(px[i], py[i]); paths[b].lineTo(px[j], py[j]);\n            }\n          }\n        }\n      }\n    }\n    ctx.lineWidth = 1; ctx.lineCap = \"round\";\n    for (b = 0; b < BUCKETS; b++) { ctx.strokeStyle = rgba(ca, (0.08 + (b + 1) / BUCKETS * 0.5).toFixed(2)); ctx.stroke(paths[b]); }\n    if (hasPtr) {\n      var pr = L * 1.7, pr2 = pr * pr, pp = new Path2D(), pp2 = new Path2D();\n      for (i = 0; i < n; i++) {\n        dx = px[i] - mx; dy = py[i] - my; d2 = dx * dx + dy * dy;\n        if (d2 < pr2) { (d2 < pr2 * 0.4 ? pp2 : pp).moveTo(mx, my); (d2 < pr2 * 0.4 ? pp2 : pp).lineTo(px[i], py[i]); }\n      }\n      ctx.strokeStyle = rgba(cb, 0.28); ctx.stroke(pp);\n      ctx.strokeStyle = rgba(cb, 0.7); ctx.stroke(pp2);\n      ctx.fillStyle = rgba(cb, 0.95); ctx.beginPath(); ctx.arc(mx, my, 3.2, 0, 6.2832); ctx.fill();\n      ctx.strokeStyle = rgba(cb, 0.35); ctx.beginPath(); ctx.arc(mx, my, 9, 0, 6.2832); ctx.stroke();\n    }\n    ctx.fillStyle = rgba(ca, 0.95);\n    for (i = 0; i < n; i++) { ctx.beginPath(); ctx.arc(px[i], py[i], sz[i], 0, 6.2832); ctx.fill(); }\n  }\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    var dt = Math.min(0.05, (now - last) / 1000 || 0.016); last = now;\n    if (!visible || document.hidden) return;\n    step(dt); render();\n  }\n  function onMove(e) {\n    var r = wrap.getBoundingClientRect(); mx = e.clientX - r.left; my = e.clientY - r.top; hasPtr = true;\n    if (reduce) render();\n  }\n  function onLeave() { hasPtr = false; if (reduce) render(); }\n  function update(partial) {\n    opts = Object.assign({ density: 1.8, linkDistance: 110, speed: 1, colorA: \"#e6ff55\", colorB: \"#fbf8f1\" }, opts, partial || {});\n    ca = rgb(opts.colorA, \"e6ff55\"); cb = rgb(opts.colorB, \"fbf8f1\");\n    if (px) populate();\n    if (reduce && !destroyed && px) render();\n  }\n\n  update(o);\n  size();\n  if (reduce) render();\n  wrap.addEventListener(\"pointermove\", onMove);\n  wrap.addEventListener(\"pointerdown\", onMove);\n  wrap.addEventListener(\"pointerleave\", onLeave);\n  if (!reduce) {\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\n    last = performance.now(); raf = requestAnimationFrame(loop);\n  }\n  if (\"ResizeObserver\" in window) { ro = new ResizeObserver(function () { if (destroyed) return; size(); if (reduce) render(); }); ro.observe(wrap); }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf);\n      wrap.removeEventListener(\"pointermove\", onMove); wrap.removeEventListener(\"pointerdown\", onMove); wrap.removeEventListener(\"pointerleave\", onLeave);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n    }\n  };\n}"
  }
}