{
  "id": "physics-glow-spheres",
  "kind": "element",
  "title": "Physics glow spheres",
  "summary": "Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.",
  "url": "https://enrichr.dev/elements/physics-glow-spheres.html",
  "section": "background",
  "techniques": [
    "webgl",
    "pointer-interaction"
  ],
  "stack": [
    "Vanilla JS",
    "WebGL"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "playful",
    "polished"
  ],
  "intents": [
    "3d spheres physics background",
    "interactive glowing balls",
    "pointer push spheres webgl",
    "glossy orbs hero background",
    "ray traced spheres shader"
  ],
  "status": "tested",
  "params": [
    {
      "key": "scheme",
      "label": "Colour palette (a click cycles it)",
      "type": "select",
      "options": [
        [
          "enrichr",
          "Enrichr"
        ],
        [
          "indigo",
          "Indigo and pink"
        ],
        [
          "amber",
          "Amber and violet"
        ],
        [
          "rose",
          "Rose and blue"
        ],
        [
          "frost",
          "White and rose"
        ]
      ],
      "value": "enrichr"
    },
    {
      "key": "lights",
      "label": "Orbiting lights",
      "type": "select",
      "options": [
        [
          "1",
          "On"
        ],
        [
          "0",
          "Off"
        ]
      ],
      "value": "1"
    },
    {
      "key": "orbit",
      "label": "Light orbit speed (radians a second)",
      "type": "range",
      "min": 0,
      "max": 2,
      "step": 0.05,
      "value": 0.4
    },
    {
      "key": "pushStrength",
      "label": "Pointer push strength",
      "type": "range",
      "min": 0,
      "max": 60,
      "step": 1,
      "value": 25
    },
    {
      "key": "pushRadius",
      "label": "Pointer push radius (scene units)",
      "type": "range",
      "min": 1,
      "max": 8,
      "step": 0.1,
      "value": 4.5
    },
    {
      "key": "glow",
      "label": "Glow (emissive strength)",
      "type": "range",
      "min": 0,
      "max": 1.5,
      "step": 0.05,
      "value": 0.65
    },
    {
      "key": "fog",
      "label": "Fog density",
      "type": "range",
      "min": 0,
      "max": 0.05,
      "step": 0.001,
      "value": 0.012
    },
    {
      "key": "light1",
      "label": "Light 1 colour",
      "type": "color",
      "value": "#fbf8f1"
    },
    {
      "key": "light2",
      "label": "Light 2 colour",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "light3",
      "label": "Light 3 colour",
      "type": "color",
      "value": "#4b1a9a"
    },
    {
      "key": "background",
      "label": "Background and fog",
      "type": "color",
      "value": "#0c1e18"
    }
  ],
  "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 \"Physics glow spheres\" element to this project.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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/physics-glow-spheres.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 \"Physics glow spheres\" 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 \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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 \"Physics glow spheres\" element to this codebase.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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-physics-glow-spheres.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Physics glow spheres 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 \"Physics glow spheres\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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- physics-glow-spheres.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 \"./physics-glow-spheres\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function PhysicsGlowSpheres(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 \"Physics glow spheres\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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- physics-glow-spheres.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/PhysicsGlowSpheres.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./physics-glow-spheres\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function PhysicsGlowSpheres(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 \"Physics glow spheres\" element.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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), physics-glow-spheres.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 \"Physics glow spheres\" element. No packages, no server code.\n\nThis is the \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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 physics-glow-spheres.js and then main.js), style.css (the CSS below), physics-glow-spheres.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 \"Physics glow spheres\" 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 \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.json\n\nWhat it does: The physics is a small solver written to match cannon.js as the original pen used it: no gravity, fixed steps of 1/60 of a second (up to three a frame), linear damping of 0.35, and sphere contacts solved like cannon's default contact (Spook stiffness 10 million, relaxation 3, no bounce, ten Gauss-Seidel passes). Every frame each sphere further than the square root of 30 from the centre is pulled back with a force of -0.6 times its position, and each sphere within the push radius of the pointer is pushed away with (1 - distance / radius) times the strength. The pointer is also a 1.5-unit sphere the balls collide with; its position is where the camera ray meets the z = 0 plane. The picture is one fragment shader: for each pixel it intersects the ray with all 18 spheres and keeps the nearest, smoothing the silhouette over one pixel. It shades the hit like the original MeshPhysicalMaterial (metalness 0.85, roughness 0.15, clearcoat 1, emissive glow) under three point lights on a ring tilted 45 degrees, then applies ACES filmic tone mapping at exposure 1.3 and exponential fog towards the background. A palette change eases each colour 10% of the way every frame.\nAccessibility: The canvas has a text label. The Change palette button does the same as a click on the scene, works with Enter and Space, and the new palette name is announced through a polite live region. With prefers-reduced-motion the spheres settle first and one still frame is drawn; the button still changes the palette instantly. Nothing flashes.\n\nTunable settings:\n- Colour palette (a click cycles it): select (Enrichr / Indigo and pink / Amber and violet / Rose and blue / White and rose), default enrichr\n- Orbiting lights: select (On / Off), default 1\n- Light orbit speed (radians a second): range 0 to 2, step 0.05, default 0.4\n- Pointer push strength: range 0 to 60, step 1, default 25\n- Pointer push radius (scene units): range 1 to 8, step 0.1, default 4.5\n- Glow (emissive strength): range 0 to 1.5, step 0.05, default 0.65\n- Fog density: range 0 to 0.05, step 0.001, default 0.012\n- Light 1 colour: color, default #fbf8f1\n- Light 2 colour: color, default #e6ff55\n- Light 3 colour: color, default #4b1a9a\n- Background and fog: color, default #0c1e18\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/physics-glow-spheres.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 \"Physics glow spheres\" 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 \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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 PhysicsGlowSpheres.\n2. Paste the JavaScript below into a separate code file named physics-glow-spheres.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 \"./physics-glow-spheres\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function PhysicsGlowSpheres(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(PhysicsGlowSpheres, {\n  scheme: { type: ControlType.Enum, title: \"Colour palette (a click cycles it)\", options: [\"enrichr\",\"indigo\",\"amber\",\"rose\",\"frost\"], optionTitles: [\"Enrichr\",\"Indigo and pink\",\"Amber and violet\",\"Rose and blue\",\"White and rose\"], defaultValue: \"enrichr\" },\n  lights: { type: ControlType.Enum, title: \"Orbiting lights\", options: [\"1\",\"0\"], optionTitles: [\"On\",\"Off\"], defaultValue: \"1\" },\n  orbit: { type: ControlType.Number, title: \"Light orbit speed\", min: 0, max: 2, step: 0.05, defaultValue: 0.4 },\n  pushStrength: { type: ControlType.Number, title: \"Pointer push strength\", min: 0, max: 60, step: 1, defaultValue: 25 },\n  pushRadius: { type: ControlType.Number, title: \"Pointer push radius\", min: 1, max: 8, step: 0.1, defaultValue: 4.5 },\n  glow: { type: ControlType.Number, title: \"Glow\", min: 0, max: 1.5, step: 0.05, defaultValue: 0.65 },\n  fog: { type: ControlType.Number, title: \"Fog density\", min: 0, max: 0.05, step: 0.001, defaultValue: 0.012 },\n  light1: { type: ControlType.Color, title: \"Light 1 colour\", defaultValue: \"#fbf8f1\" },\n  light2: { type: ControlType.Color, title: \"Light 2 colour\", defaultValue: \"#e6ff55\" },\n  light3: { type: ControlType.Color, title: \"Light 3 colour\", defaultValue: \"#4b1a9a\" },\n  background: { type: ControlType.Color, title: \"Background and fog\", defaultValue: \"#0c1e18\" },\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 \"Physics glow spheres\" 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 \"Physics glow spheres\" element from the Enrichr Library: Eighteen glossy glowing spheres huddle in the middle, knock into each other, get shoved aside by the pointer and are lit by three coloured lights that circle them; a click changes the palette.\nPage: https://enrichr.dev/elements/physics-glow-spheres.html\nMachine-readable spec: https://enrichr.dev/elements/physics-glow-spheres.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-physics-glow-spheres\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-physics-glow-spheres\"), { ...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 has a text label. The Change palette button does the same as a click on the scene, works with Enter and Space, and the new palette name is announced through a polite live region. With prefers-reduced-motion the spheres settle first and one still frame is drawn; the button still changes the palette instantly. Nothing flashes.",
  "performance": "The physics is about 170 pair checks a step, so it costs almost nothing. The shader tests 18 spheres per pixel and shades one (two on silhouette edges), which is light on any graphics card but is the heaviest part, so the pixel ratio is capped at 2, the loop pauses off screen and in hidden tabs, and destroy() frees the WebGL context. Without WebGL the CSS background stays and the button is hidden.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/RNpEBEB",
  "source": {
    "markup": "<div class=\"ef-orbs\"><canvas class=\"ef-orbs__c\" role=\"img\" aria-label=\"Eighteen glossy glowing spheres huddled in the middle, pushed apart by the pointer and lit by three coloured lights that circle them\"></canvas><button class=\"ef-orbs__btn\" type=\"button\">Change palette</button><span class=\"ef-orbs__live\" aria-live=\"polite\"></span></div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-orbs { position: relative; width: 100%; min-height: 24rem; overflow: hidden; border-radius: 1rem; background: radial-gradient(circle at 50% 50%, rgba(230, 255, 85, 0.14), rgba(230, 255, 85, 0) 42%), var(--ef-orbs-bg, #0c1e18); cursor: pointer; touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }\n.ef-orbs .ef-orbs__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.ef-orbs .ef-orbs__btn { position: absolute; top: 1rem; left: 50%; z-index: 1; transform: translateX(-50%); margin: 0; padding: 0.55rem 1.15rem; border-radius: 999px; border: 1px solid rgba(251, 248, 241, 0.16); background: rgba(12, 30, 24, 0.82); color: #fbf8f1; font: 500 0.75rem/1 'Parkinsans', 'Space Grotesk', sans-serif; letter-spacing: 0.02em; cursor: pointer; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1); }\n.ef-orbs .ef-orbs__btn:hover { transform: translateX(-50%) translateY(-2px); background: rgba(12, 30, 24, 0.95); border-color: rgba(251, 248, 241, 0.3); box-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.4); }\n.ef-orbs .ef-orbs__btn:focus-visible { outline: 2px solid #e6ff55; outline-offset: 3px; }\n.ef-orbs .ef-orbs__live { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n@media (prefers-reduced-motion: reduce) { .ef-orbs .ef-orbs__btn { transition: none; } .ef-orbs .ef-orbs__btn:hover { transform: translateX(-50%); } }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Physics glow spheres: eighteen glossy, glowing spheres huddle in the middle of the box. A centring force pulls back any\n// sphere that drifts more than about 5.5 units out, the pointer shoves nearby spheres away, and the spheres knock into\n// each other. Three coloured point lights circle the group on a tilted ring. Click (or the button) cycles the palette and\n// the colours ease across.\n// No libraries. The physics is a small sphere solver written to match cannon.js as the original pen used it: fixed 1/60 s\n// steps (up to three per frame), contacts solved like cannon's default contact (Spook stiffness 1e7, relaxation 3, no\n// bounce, ten Gauss-Seidel passes), linear damping 0.35, a centring force of -0.6 x position once a sphere is more than\n// root 30 from the centre, and a pointer push of (1 - distance / radius) x strength inside the push radius, plus a\n// 1.5-unit pointer sphere that the balls collide with. The picture is one WebGL1 fragment shader that ray-traces the\n// spheres analytically (nearest hit per pixel, edges smoothed over one pixel) and shades them like the original\n// MeshPhysicalMaterial (metalness 0.85, roughness 0.15, clearcoat 1, emissive glow) under the three point lights and a\n// soft ambient, with ACES filmic tone mapping (exposure 1.3) and exponential fog towards the background colour.\n// Reduced motion settles the spheres first, then draws one still frame (the palette button still works). The loop\n// pauses off screen and in hidden tabs. Without WebGL the CSS background stays.\n// mount(root, { scheme (colour palette), lights (\"1\" on, \"0\" off), orbit (light orbit speed, radians a second),\n//               pushStrength (pointer push), pushRadius (pointer reach, scene units), glow (emissive strength),\n//               fog (fog density), light1, light2, light3 (light colours), background (background and fog colour) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-orbs\");\n  var canvas = root.querySelector(\".ef-orbs__c\");\n  var btn = root.querySelector(\".ef-orbs__btn\");\n  var live = root.querySelector(\".ef-orbs__live\");\n  var opts = {}, raf = 0, visible = true, io = null, ro = null, destroyed = false, last = 0;\n  var gl = null, prog = null, vb = null, u = {}, ok = false;\n\n  var N = 18, R = 1.1, PR = 1.5, H = 1 / 60, CAMZ = 35, TANH = Math.tan(9 * Math.PI / 180);\n  var SA = 4 / (H * (1 + 4 * 3)), SB = (4 * 3) / (1 + 4 * 3), SEPS = 4 / (H * H * 1e7 * (1 + 4 * 3));\n  var DAMP = Math.pow(1 - 0.35, H), MAXC = N * (N - 1) / 2 + N;\n  var px = new Float64Array(N), py = new Float64Array(N), pz = new Float64Array(N);\n  var vx = new Float64Array(N), vy = new Float64Array(N), vz = new Float64Array(N);\n  var fx = new Float64Array(N), fy = new Float64Array(N), fz = new Float64Array(N);\n  var lx = new Float64Array(N), ly = new Float64Array(N), lz = new Float64Array(N);\n  var ci = new Int16Array(MAXC), cj = new Int16Array(MAXC), cnx = new Float64Array(MAXC), cny = new Float64Array(MAXC), cnz = new Float64Array(MAXC);\n  var cB = new Float64Array(MAXC), cInv = new Float64Array(MAXC), cLam = new Float64Array(MAXC);\n  // the kinematic pointer sphere starts at the centre, as in the original, until the pointer first moves\n  var ptr = [0, 0, 0], hasPointer = false, simTime = 0, lightAngle = 0;\n\n  var SCHEMES = {\n    enrichr: [\"#e6ff55\", \"#1a7a4c\", \"#fbf8f1\", \"#4b1a9a\"],\n    indigo: [\"#6366f1\", \"#ec4899\", \"#38bdf8\", \"#10b981\"],\n    amber: [\"#f59e0b\", \"#ef4444\", \"#8b5cf6\", \"#06b6d4\"],\n    rose: [\"#f43f5e\", \"#a855f7\", \"#3b82f6\", \"#14b8a6\"],\n    frost: [\"#ffffff\", \"#f43f5e\", \"#38bdf8\", \"#a855f7\"]\n  };\n  var ORDER = [\"enrichr\", \"indigo\", \"amber\", \"rose\", \"frost\"];\n  var NAMES = { enrichr: \"Enrichr\", indigo: \"Indigo and pink\", amber: \"Amber and violet\", rose: \"Rose and blue\", frost: \"White and rose\" };\n  var LOCAL = [[-8, 6, -5], [8, -6, 2], [0, 8, -8]], POWER = [60, 50, 40];\n  var DEF = { scheme: \"enrichr\", lights: \"1\", orbit: 0.4, pushStrength: 25, pushRadius: 4.5, glow: 0.65, fog: 0.012, light1: \"#fbf8f1\", light2: \"#e6ff55\", light3: \"#4b1a9a\", background: \"#0c1e18\" };\n  var pal = 0, cur = [], goal = [];\n  var bufP = new Float32Array(N * 3), bufC = new Float32Array(12), bufLP = new Float32Array(9), bufLC = new Float32Array(9);\n\n  var VS = \"attribute vec2 p;void main(){gl_Position=vec4(p,0.0,1.0);}\";\n  var FS = [\n    \"#ifdef GL_FRAGMENT_PRECISION_HIGH\", \"precision highp float;\", \"#else\", \"precision mediump float;\", \"#endif\",\n    \"uniform vec2 uRes;uniform vec3 uP[18];uniform vec3 uC[4];uniform vec3 uLP[3];uniform vec3 uLC[3];uniform vec3 uBg;\",\n    \"uniform float uGlow;uniform float uFog;uniform float uTan;\",\n    \"const float R=1.1;const float PI=3.141592653589793;const vec3 CAM=vec3(0.0,0.0,35.0);\",\n    // three.js r128 ACES filmic tone mapping\n    \"vec3 rrt(vec3 v){vec3 a=v*(v+0.0245786)-0.000090537;vec3 b=v*(0.983729*v+0.4329510)+0.238081;return a/b;}\",\n    \"vec3 aces(vec3 c){mat3 mi=mat3(vec3(0.59719,0.07600,0.02840),vec3(0.35458,0.90834,0.13383),vec3(0.04823,0.01566,0.83777));\",\n    \"mat3 mo=mat3(vec3(1.60475,-0.10208,-0.00327),vec3(-0.53108,1.10813,-0.07276),vec3(-0.07367,-0.00605,1.07602));\",\n    \"c*=1.3/0.6;c=mi*c;c=rrt(c);c=mo*c;return clamp(c,0.0,1.0);}\",\n    // GGX specular with Schlick fresnel and Smith visibility, as in three.js r128\n    \"vec3 ggx(vec3 L,vec3 V,vec3 N,vec3 f0,float rough){float a=rough*rough;float a2=a*a;vec3 h=normalize(L+V);\",\n    \"float nl=clamp(dot(N,L),0.0,1.0);float nv=clamp(dot(N,V),0.0,1.0);float nh=clamp(dot(N,h),0.0,1.0);float lh=clamp(dot(L,h),0.0,1.0);\",\n    \"vec3 F=(1.0-f0)*exp2((-5.55473*lh-6.98316)*lh)+f0;\",\n    \"float gv=nl*sqrt(a2+(1.0-a2)*nv*nv);float gl=nv*sqrt(a2+(1.0-a2)*nl*nl);float G=0.5/max(gv+gl,1e-6);\",\n    \"float d=nh*nh*(a2-1.0)+1.0;return F*(G*a2/(PI*d*d));}\",\n    \"vec3 col4(int i){int m=i-(i/4)*4;if(m==0)return uC[0];if(m==1)return uC[1];if(m==2)return uC[2];return uC[3];}\",\n    // metalness 0.85, roughness 0.15, reflectivity 0.9, clearcoat 1 (roughness 0.1), ambient 1.5, emissive = colour x glow\n    \"vec3 shade(vec3 P,vec3 N,vec3 base,float gr){vec3 V=normalize(CAM-P);vec3 diff=base*0.15;vec3 spec=mix(vec3(0.1296),base,0.85);\",\n    \"float rs=min(0.15+gr,1.0);float rc=min(0.1+gr,1.0);vec3 col=1.5*diff;\",\n    \"for(int k=0;k<3;k++){vec3 lv=uLP[k]-P;float dist=length(lv);vec3 L=lv/dist;float nl=clamp(dot(N,L),0.0,1.0);\",\n    \"vec3 irr=uLC[k]*(clamp(1.0-dist/60.0,0.0,1.0)*nl*PI);float cc=0.04+0.96*pow(1.0-nl,5.0)*(1.0-rc)*(1.0-rc);\",\n    \"col+=irr*ggx(L,V,N,vec3(0.04),rc);col+=(1.0-cc)*irr*(ggx(L,V,N,spec,rs)+diff/PI);}\",\n    \"col+=base*uGlow;col=aces(col);float z=CAM.z-P.z;return mix(col,uBg,1.0-exp(-uFog*uFog*z*z));}\",\n    \"void main(){vec2 ndc=gl_FragCoord.xy/uRes*2.0-1.0;vec3 rd=normalize(vec3(ndc.x*uTan*uRes.x/uRes.y,ndc.y*uTan,-1.0));\",\n    \"float pk=2.0*uTan/uRes.y;float tb=1e9;int ib=-1;vec3 cb=vec3(0.0);float cov=0.0;\",\n    \"for(int i=0;i<18;i++){vec3 oc=uP[i]-CAM;float b=dot(oc,rd);if(b<=0.0)continue;float d2=max(dot(oc,oc)-b*b,0.0);\",\n    \"float pw=pk*b;float rr=R+0.5*pw;if(d2>rr*rr)continue;float t=b-sqrt(max(R*R-d2,0.0));\",\n    \"if(t<tb){tb=t;ib=i;cb=uP[i];cov=clamp((rr-sqrt(d2))/pw,0.0,1.0);}}\",\n    \"if(ib<0){gl_FragColor=vec4(uBg,1.0);return;}\",\n    \"vec3 P=CAM+rd*tb;vec3 col=shade(P,normalize(P-cb),col4(ib),pk*tb/R);\",\n    \"if(cov<1.0){float t2=1e9;int i2=-1;vec3 c2=vec3(0.0);\",\n    \"for(int i=0;i<18;i++){if(i==ib)continue;vec3 oc=uP[i]-CAM;float b=dot(oc,rd);float d2=dot(oc,oc)-b*b;if(b<=0.0||d2>R*R)continue;\",\n    \"float t=b-sqrt(R*R-d2);if(t<t2){t2=t;i2=i;c2=uP[i];}}\",\n    \"vec3 back=uBg;if(i2>=0){vec3 P2=CAM+rd*t2;back=shade(P2,normalize(P2-c2),col4(i2),pk*t2/R);}col=mix(back,col,cov);}\",\n    \"gl_FragColor=vec4(col,1.0);}\"\n  ].join(\"\\n\");\n\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\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) / 255, ((v >> 8) & 255) / 255, (v & 255) / 255]; }\n\n  // ---------- physics: a cannon.js-style world with no gravity ----------\n  function scatter() {\n    for (var i = 0; i < N; i++) {\n      px[i] = (Math.random() - 0.5) * 14; py[i] = (Math.random() - 0.5) * 14; pz[i] = (Math.random() - 0.5) * 14;\n      vx[i] = vy[i] = vz[i] = 0; fx[i] = fy[i] = fz[i] = 0;\n    }\n  }\n  // one contact: body a (-1 = the pointer sphere, which never moves) against sphere b, normal from a to b\n  function contact(k, a, b, ax, ay, az, rsum) {\n    var dx = px[b] - ax, dy = py[b] - ay, dz = pz[b] - az, d2 = dx * dx + dy * dy + dz * dz;\n    if (d2 >= rsum * rsum) return k;\n    var d = Math.sqrt(d2);\n    if (d < 1e-9) { dx = 1; dy = 0; dz = 0; d = 1e-9; } else { dx /= d; dy /= d; dz /= d; }\n    var ia = a < 0 ? 0 : 1, g = d - rsum;\n    var vrel = (vx[b] * dx + vy[b] * dy + vz[b] * dz) - (a < 0 ? 0 : vx[a] * dx + vy[a] * dy + vz[a] * dz);\n    var fm = (fx[b] * dx + fy[b] * dy + fz[b] * dz) - (a < 0 ? 0 : fx[a] * dx + fy[a] * dy + fz[a] * dz);\n    ci[k] = a; cj[k] = b; cnx[k] = dx; cny[k] = dy; cnz[k] = dz;\n    cB[k] = -g * SA - vrel * SB - H * fm; // restitution 0, so (1 + e) = 1\n    cInv[k] = 1 / (ia + 1 + SEPS); cLam[k] = 0;\n    return k + 1;\n  }\n  function internalStep() {\n    var n = 0, i, j, it, k;\n    for (i = 0; i < N; i++) {\n      for (j = i + 1; j < N; j++) n = contact(n, i, j, px[i], py[i], pz[i], R * 2);\n      n = contact(n, -1, i, ptr[0], ptr[1], ptr[2], R + PR);\n    }\n    for (i = 0; i < N; i++) lx[i] = ly[i] = lz[i] = 0;\n    for (it = 0; it < 10; it++) {\n      var tot = 0;\n      for (k = 0; k < n; k++) {\n        var a = ci[k], b = cj[k], nx = cnx[k], ny = cny[k], nz = cnz[k];\n        var gwl = (lx[b] * nx + ly[b] * ny + lz[b] * nz) - (a < 0 ? 0 : lx[a] * nx + ly[a] * ny + lz[a] * nz);\n        var dl = cInv[k] * (cB[k] - gwl - SEPS * cLam[k]);\n        if (cLam[k] + dl < 0) dl = -cLam[k];\n        cLam[k] += dl; tot += dl > 0 ? dl : -dl;\n        lx[b] += nx * dl; ly[b] += ny * dl; lz[b] += nz * dl;\n        if (a >= 0) { lx[a] -= nx * dl; ly[a] -= ny * dl; lz[a] -= nz * dl; }\n      }\n      if (tot * tot < 1e-14) break;\n    }\n    for (i = 0; i < N; i++) {\n      vx[i] = (vx[i] + lx[i]) * DAMP; vy[i] = (vy[i] + ly[i]) * DAMP; vz[i] = (vz[i] + lz[i]) * DAMP;\n      vx[i] += fx[i] * H; vy[i] += fy[i] * H; vz[i] += fz[i] * H;\n      px[i] += vx[i] * H; py[i] += vy[i] * H; pz[i] += vz[i] * H;\n      fx[i] = fy[i] = fz[i] = 0;\n    }\n  }\n  // forces are added once a frame, like applyForce in the original's animation loop; k scales them so a 120 Hz screen\n  // pushes as hard as a 60 Hz one\n  function addForces(k) {\n    var R2 = opts.pushRadius, S = opts.pushStrength;\n    for (var i = 0; i < N; i++) {\n      var x = px[i], y = py[i], z = pz[i];\n      if (x * x + y * y + z * z > 30) { fx[i] -= x * 0.6 * k; fy[i] -= y * 0.6 * k; fz[i] -= z * 0.6 * k; }\n      if (hasPointer) {\n        var dx = x - ptr[0], dy = y - ptr[1], dz = z - ptr[2], d = Math.sqrt(dx * dx + dy * dy + dz * dz);\n        if (d < R2 && d > 0.001) { var f = (1 - d / R2) * S * k / d; fx[i] += dx * f; fy[i] += dy * f; fz[i] += dz * f; }\n      }\n    }\n  }\n  // world.step(1/60, delta, 3): as many fixed steps as the clock has crossed, at most three\n  function stepWorld(delta) {\n    var steps = Math.min(3, Math.floor((simTime + delta) / H) - Math.floor(simTime / H));\n    for (var s = 0; s < steps; s++) internalStep();\n    simTime += delta;\n  }\n  function settle(frames) { for (var s = 0; s < frames; s++) { internalStep(); addForces(1); } }\n\n  // ---------- colours ----------\n  function setScheme(idx, snap) {\n    pal = ((idx % ORDER.length) + ORDER.length) % ORDER.length;\n    var list = SCHEMES[ORDER[pal]];\n    for (var k = 0; k < 4; k++) { goal[k] = rgb(list[k], \"e6ff55\"); if (snap || !cur[k]) cur[k] = goal[k].slice(); }\n  }\n  function easeColours(delta) {\n    var t = 1 - Math.pow(0.9, delta * 60); // lerp(target, 0.1) every frame at 60 fps\n    for (var k = 0; k < 4; k++) for (var c = 0; c < 3; c++) cur[k][c] += (goal[k][c] - cur[k][c]) * t;\n  }\n\n  // ---------- WebGL ----------\n  function sh(type, src) { var s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return gl.getShaderParameter(s, gl.COMPILE_STATUS) ? s : null; }\n  function setup() {\n    var v = sh(gl.VERTEX_SHADER, VS), f = sh(gl.FRAGMENT_SHADER, FS);\n    if (!v || !f) return false;\n    prog = gl.createProgram(); gl.attachShader(prog, v); gl.attachShader(prog, f); gl.linkProgram(prog);\n    gl.deleteShader(v); gl.deleteShader(f);\n    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return false;\n    gl.useProgram(prog);\n    vb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vb);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    var loc = gl.getAttribLocation(prog, \"p\"); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\n    [\"uRes\", \"uP\", \"uC\", \"uLP\", \"uLC\", \"uBg\", \"uGlow\", \"uFog\", \"uTan\"].forEach(function (k) { u[k] = gl.getUniformLocation(prog, k); });\n    return true;\n  }\n  function size() {\n    var dpr = Math.min(window.devicePixelRatio || 1, 2);\n    var w = Math.max(1, Math.round(wrap.clientWidth * dpr)), h = Math.max(1, Math.round(wrap.clientHeight * dpr));\n    if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; gl.viewport(0, 0, w, h); }\n  }\n  function draw() {\n    if (!ok || destroyed || gl.isContextLost()) return;\n    size();\n    var i, k;\n    for (i = 0; i < N; i++) { bufP[i * 3] = px[i]; bufP[i * 3 + 1] = py[i]; bufP[i * 3 + 2] = pz[i]; }\n    for (k = 0; k < 4; k++) { bufC[k * 3] = cur[k][0]; bufC[k * 3 + 1] = cur[k][1]; bufC[k * 3 + 2] = cur[k][2]; }\n    // the light group: tilted -45 degrees about x, turning about its own y axis (three.js Euler order XYZ)\n    var ca = Math.cos(lightAngle), sa = Math.sin(lightAngle), cx = Math.cos(-Math.PI / 4), sx = Math.sin(-Math.PI / 4);\n    var on = opts.lights !== \"0\" && opts.lights !== 0 && opts.lights !== false;\n    var cols = [rgb(opts.light1, \"fbf8f1\"), rgb(opts.light2, \"e6ff55\"), rgb(opts.light3, \"4b1a9a\")];\n    for (k = 0; k < 3; k++) {\n      var L = LOCAL[k], x1 = ca * L[0] + sa * L[2], y1 = L[1], z1 = -sa * L[0] + ca * L[2];\n      bufLP[k * 3] = x1; bufLP[k * 3 + 1] = cx * y1 - sx * z1; bufLP[k * 3 + 2] = sx * y1 + cx * z1;\n      for (var c = 0; c < 3; c++) bufLC[k * 3 + c] = on ? cols[k][c] * POWER[k] : 0;\n    }\n    gl.uniform2f(u.uRes, canvas.width, canvas.height);\n    gl.uniform3fv(u.uP, bufP); gl.uniform3fv(u.uC, bufC);\n    gl.uniform3fv(u.uLP, bufLP); gl.uniform3fv(u.uLC, bufLC);\n    gl.uniform3fv(u.uBg, rgb(opts.background, \"0c1e18\"));\n    gl.uniform1f(u.uGlow, opts.glow); gl.uniform1f(u.uFog, opts.fog); gl.uniform1f(u.uTan, TANH);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n  }\n\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    var delta = Math.min(0.1, Math.max(0, (now - last) / 1000)); last = now;\n    if (!visible || document.hidden) return;\n    stepWorld(delta);\n    lightAngle += delta * opts.orbit;\n    addForces(delta * 60);\n    easeColours(delta);\n    draw();\n  }\n\n  // ---------- input ----------\n  function onMove(e) {\n    var r = wrap.getBoundingClientRect();\n    if (!r.width || !r.height) return;\n    var nx = (e.clientX - r.left) / r.width * 2 - 1, ny = -((e.clientY - r.top) / r.height) * 2 + 1;\n    // the ray from the camera meets the z = 0 plane at a distance of 35\n    ptr[0] = CAMZ * nx * TANH * (r.width / r.height); ptr[1] = CAMZ * ny * TANH; ptr[2] = 0;\n    hasPointer = true;\n  }\n  function onLeave() { hasPointer = false; ptr[0] = ptr[1] = ptr[2] = -100; }\n  function cycle() {\n    setScheme(pal + 1, reduce);\n    if (live) live.textContent = \"Palette: \" + NAMES[ORDER[pal]];\n    if (reduce) draw();\n  }\n  function onLost(e) { e.preventDefault(); canvas.style.display = \"none\"; if (btn) btn.hidden = true; }\n\n  function update(partial) {\n    partial = partial || {};\n    opts = Object.assign({}, DEF, opts, partial);\n    [\"orbit\", \"pushStrength\", \"pushRadius\", \"glow\", \"fog\"].forEach(function (k) { opts[k] = Math.max(0, num(opts[k], DEF[k])); });\n    opts.pushRadius = Math.max(0.1, opts.pushRadius);\n    if (!cur.length || \"scheme\" in partial) { var i = ORDER.indexOf(String(opts.scheme)); setScheme(i < 0 ? 0 : i, reduce || !cur.length); }\n    wrap.style.setProperty(\"--ef-orbs-bg\", opts.background);\n    if (destroyed) return;\n    draw();\n  }\n\n  scatter();\n  try { gl = canvas.getContext(\"webgl\", { antialias: false, alpha: false, powerPreference: \"high-performance\" }); } catch (e) { gl = null; }\n  ok = !!gl && setup();\n  if (!ok) { canvas.style.display = \"none\"; if (btn) btn.hidden = true; }\n  else canvas.addEventListener(\"webglcontextlost\", onLost);\n  if (reduce) { opts = Object.assign({}, DEF, o || {}); settle(300); lightAngle = 1.2; }\n  update(o);\n  if (ok) {\n    wrap.addEventListener(\"click\", cycle);\n    if (!reduce) {\n      wrap.addEventListener(\"pointermove\", onMove);\n      wrap.addEventListener(\"pointerleave\", onLeave);\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) draw(); }); ro.observe(wrap); }\n  }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf);\n      wrap.removeEventListener(\"click\", cycle);\n      wrap.removeEventListener(\"pointermove\", onMove);\n      wrap.removeEventListener(\"pointerleave\", onLeave);\n      canvas.removeEventListener(\"webglcontextlost\", onLost);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n      if (gl) {\n        var ext = gl.getExtension(\"WEBGL_lose_context\");\n        if (vb) gl.deleteBuffer(vb); if (prog) gl.deleteProgram(prog);\n        if (ext) ext.loseContext();\n        gl = null;\n      }\n    }\n  };\n}"
  }
}