{
  "id": "audio-pulse-distortion",
  "kind": "element",
  "title": "Audio pulse distortion",
  "summary": "A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.",
  "url": "https://enrichr.dev/elements/audio-pulse-distortion.html",
  "section": "hero",
  "techniques": [
    "webgl"
  ],
  "stack": [
    "Vanilla JS",
    "WebGL",
    "Web Audio"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "bold",
    "kinetic"
  ],
  "intents": [
    "audio reactive image",
    "music visualiser webgl",
    "beat distortion effect",
    "bass pulse shader",
    "microphone reactive visual"
  ],
  "status": "tested",
  "params": [
    {
      "key": "bpm",
      "label": "Beats per minute",
      "type": "range",
      "min": 60,
      "max": 180,
      "step": 1,
      "value": 110
    },
    {
      "key": "intensity",
      "label": "Intensity",
      "type": "range",
      "min": 0,
      "max": 2,
      "step": 0.05,
      "value": 1
    },
    {
      "key": "mic",
      "label": "Microphone",
      "type": "select",
      "options": [
        [
          "0",
          "Off (built-in beat)"
        ],
        [
          "1",
          "On (asks permission)"
        ]
      ],
      "value": "0"
    },
    {
      "key": "colorA",
      "label": "Artwork green",
      "type": "color",
      "value": "#005236"
    },
    {
      "key": "colorB",
      "label": "Artwork accent",
      "type": "color",
      "value": "#e6ff55"
    }
  ],
  "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 \"Audio pulse distortion\" element to this project.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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/audio-pulse-distortion.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 \"Audio pulse distortion\" 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 \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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 \"Audio pulse distortion\" element to this codebase.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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-audio-pulse-distortion.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Audio pulse distortion 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 \"Audio pulse distortion\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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- audio-pulse-distortion.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 \"./audio-pulse-distortion\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function AudioPulseDistortion(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 \"Audio pulse distortion\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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- audio-pulse-distortion.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/AudioPulseDistortion.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./audio-pulse-distortion\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function AudioPulseDistortion(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 \"Audio pulse distortion\" element.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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), audio-pulse-distortion.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 \"Audio pulse distortion\" element. No packages, no server code.\n\nThis is the \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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 audio-pulse-distortion.js and then main.js), style.css (the CSS below), audio-pulse-distortion.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 \"Audio pulse distortion\" 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 \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.json\n\nWhat it does: A small signal generator produces bass, mid and treble levels and 16 spectrum bins from a four-beat pattern of kicks, snares and hats, so the element works with no audio at all. A fragment shader reads those levels: bass zooms the picture, each kick sends a shock ring outward that pushes pixels, and treble adds a wobble and splits the red, green and blue channels. If the microphone is switched on, an analyser node supplies the same three levels and bins instead, with automatic gain so quiet rooms still move it.\nAccessibility: The microphone is never requested on load, only after a click on the button or a later update call, and the status line says what is happening, including when permission is refused. Audio is analysed only and never played, recorded or sent anywhere. Reduced motion shows the still artwork and disables the microphone button. The zoom and colour split get strong at high intensity, so keep the default or lower it on public pages.\n\nTunable settings:\n- Beats per minute: range 60 to 180, step 1, default 110\n- Intensity: range 0 to 2, step 0.05, default 1\n- Microphone: select (Off (built-in beat) / On (asks permission)), default 0\n- Artwork green: color, default #005236\n- Artwork accent: color, default #e6ff55\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/audio-pulse-distortion.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 \"Audio pulse distortion\" 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 \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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 AudioPulseDistortion.\n2. Paste the JavaScript below into a separate code file named audio-pulse-distortion.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 \"./audio-pulse-distortion\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function AudioPulseDistortion(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(AudioPulseDistortion, {\n  bpm: { type: ControlType.Number, title: \"Beats per minute\", min: 60, max: 180, step: 1, defaultValue: 110 },\n  intensity: { type: ControlType.Number, title: \"Intensity\", min: 0, max: 2, step: 0.05, defaultValue: 1 },\n  mic: { type: ControlType.Enum, title: \"Microphone\", options: [\"0\",\"1\"], optionTitles: [\"Off (built-in beat)\",\"On (asks permission)\"], defaultValue: \"0\" },\n  colorA: { type: ControlType.Color, title: \"Artwork green\", defaultValue: \"#005236\" },\n  colorB: { type: ControlType.Color, title: \"Artwork accent\", defaultValue: \"#e6ff55\" },\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 \"Audio pulse distortion\" 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 \"Audio pulse distortion\" element from the Enrichr Library: A generated record artwork that zooms, ripples and splits its colours in time with a built-in beat or your microphone.\nPage: https://enrichr.dev/elements/audio-pulse-distortion.html\nMachine-readable spec: https://enrichr.dev/elements/audio-pulse-distortion.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-audio-pulse-distortion\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-audio-pulse-distortion\"), { ...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 microphone is never requested on load, only after a click on the button or a later update call, and the status line says what is happening, including when permission is refused. Audio is analysed only and never played, recorded or sent anywhere. Reduced motion shows the still artwork and disables the microphone button. The zoom and colour split get strong at high intensity, so keep the default or lower it on public pages.",
  "performance": "One full-screen triangle with three texture reads per pixel, a capped pixel ratio of 1.5 and a loop that pauses off screen. The analyser uses 128 bins. The audio context, tracks and WebGL context are all released on destroy.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-ap\">\n  <canvas class=\"ef-ap__c\" role=\"img\" aria-label=\"A generated record artwork that pulses and distorts in time with a beat\"></canvas>\n  <div class=\"ef-ap__bars\" aria-hidden=\"true\"></div>\n  <div class=\"ef-ap__side\">\n    <button type=\"button\" class=\"ef-ap__mic\" aria-pressed=\"false\">Use microphone</button>\n    <span class=\"ef-ap__status\" role=\"status\" aria-live=\"polite\"></span>\n  </div>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-ap { position: relative; width: 100%; min-height: 20rem; overflow: hidden; border-radius: 1rem; background: #0c1e18; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.ef-ap__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transform-origin: 50% 50%; will-change: transform; }\n.ef-ap__bars { position: absolute; left: 0.9rem; bottom: 0.8rem; height: 1.8rem; display: flex; align-items: flex-end; gap: 3px; pointer-events: none; }\n.ef-ap__bars i { display: block; width: 4px; height: 100%; background: var(--ef-ap-accent, #e6ff55); border-radius: 1px; transform-origin: 50% 100%; transform: scaleY(0.08); }\n.ef-ap__side { position: absolute; right: 0.8rem; top: 0.8rem; display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; max-width: calc(100% - 1.6rem); }\n.ef-ap__mic { padding: 0.4rem 0.8rem; border-radius: 999px; border: 1.5px solid rgba(251, 248, 241, 0.7); background: rgba(12, 30, 24, 0.6); color: #fbf8f1; font: inherit; font-size: 0.75rem; letter-spacing: 0.04em; cursor: pointer; }\n.ef-ap__mic:hover:not(:disabled) { background: var(--ef-ap-accent, #e6ff55); border-color: var(--ef-ap-accent, #e6ff55); color: #0c1e18; }\n.ef-ap__mic[aria-pressed=\"true\"] { background: var(--ef-ap-accent, #e6ff55); border-color: var(--ef-ap-accent, #e6ff55); color: #0c1e18; }\n.ef-ap__mic:disabled { opacity: 0.5; cursor: default; }\n.ef-ap__mic:focus-visible { outline: 2px solid #fbf8f1; outline-offset: 2px; }\n.ef-ap__status { font-size: 0.7rem; color: #fbf8f1; background: rgba(12, 30, 24, 0.6); padding: 0.15rem 0.5rem; border-radius: 0.5rem; text-align: right; }\n.ef-ap__status:empty { display: none; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Audio pulse distortion: a generated record artwork is drawn by a WebGL shader that zooms, ripples and splits its colour channels in time with an audio-like signal.\n// By default the signal is a built-in synthetic beat, so nothing is recorded or downloaded. Pressing \"Use microphone\" (or setting mic to 1) asks the browser for the mic only then; if it is refused the beat keeps playing.\n// Nothing is played through the speakers. Without WebGL the artwork is drawn flat and pulses with a CSS scale; reduced motion shows the still artwork with no pulse.\n// mount(root, { bpm (60-180), intensity (0-2), mic (0 or 1, starts the microphone only after a click or update), colorA (artwork green), colorB (artwork accent) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-ap\");\n  var canvas = root.querySelector(\".ef-ap__c\");\n  var barsEl = root.querySelector(\".ef-ap__bars\");\n  var micBtn = root.querySelector(\".ef-ap__mic\");\n  var statusEl = root.querySelector(\".ef-ap__status\");\n  var opts = {}, gl = null, ctx2 = null, prog, u = {}, tex, art = null, raf = 0, visible = true, io = null, ro = null, destroyed = false;\n  var t0 = performance.now(), bars = [], lv = { bass: 0, mid: 0, tre: 0, k: 9, bins: new Float32Array(16) }, source = \"synth\";\n  var audio = null, micToken = 0, lastKick = 0, prevBass = 0, peak = 0.2;\n  var VS = \"attribute vec2 p;varying vec2 vUv;void main(){vUv=p*.5+.5;gl_Position=vec4(p,0.,1.);}\";\n  var FS = \"precision mediump float;varying vec2 vUv;uniform sampler2D uT;uniform float uTime,uBass,uMid,uTre,uK,uI,uAsp;uniform vec2 uS;\" +\n    \"void main(){vec2 c=vUv-.5;vec2 p=c*vec2(uAsp,1.);float r=length(p);vec2 dir=p/(r+.0001);\" +\n    \"float zoom=1.-uBass*.07*uI;float rad=uK*1.1;\" +\n    \"float ring=exp(-pow((r-rad)*10.,2.))*exp(-uK*2.6)*uI;\" +\n    \"vec2 q=c*zoom-dir*ring*.05/vec2(uAsp,1.);\" +\n    \"q.x+=sin(p.y*22.+uTime*6.)*uTre*.008*uI;\" +\n    \"float ca=(.003*uI+uTre*.012*uI+ring*.012);vec2 off=dir/vec2(uAsp,1.)*ca;\" +\n    \"vec2 b=q*uS+.5;\" +\n    \"vec3 col=vec3(texture2D(uT,clamp(b+off,0.,1.)).r,texture2D(uT,clamp(b,0.,1.)).g,texture2D(uT,clamp(b-off,0.,1.)).b);\" +\n    \"col*=1.+uBass*.1*uI+ring*.25;col+=vec3(uMid*.03*uI);\" +\n    \"col*=1.-.5*smoothstep(.5,1.1,r);gl_FragColor=vec4(col,1.);}\";\n\n  function hex(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 mix(a, b, t) { return \"rgb(\" + [0, 1, 2].map(function (i) { return Math.round(a[i] + (b[i] - a[i]) * t); }).join(\",\") + \")\"; }\n  function rgba(c, a) { return \"rgba(\" + c.join(\",\") + \",\" + a + \")\"; }\n  function seeded(s) { return function () { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; }; }\n\n  function makeArt() {\n    var W = 1280, H = 800, c = document.createElement(\"canvas\"); c.width = W; c.height = H;\n    var g = c.getContext(\"2d\"), A = hex(opts.colorA, \"005236\"), B = hex(opts.colorB, \"e6ff55\"), D = [12, 30, 24], C = [251, 248, 241], rnd = seeded(31), i;\n    var cx = W / 2, cy = H / 2, R = H * 0.46;\n    var bg = g.createRadialGradient(cx, cy, 20, cx, cy, W * 0.6); bg.addColorStop(0, mix(A, D, 0.2)); bg.addColorStop(1, mix(D, A, 0.08));\n    g.fillStyle = bg; g.fillRect(0, 0, W, H);\n    var N = 28;\n    for (i = 0; i < N; i++) {\n      var a0 = i / N * 6.2832, a1 = (i + 0.5) / N * 6.2832;\n      g.beginPath(); g.moveTo(cx, cy); g.arc(cx, cy, W, a0, a1); g.closePath();\n      g.fillStyle = i % 2 ? rgba(A, 0.55) : rgba(D, 0.35); g.fill();\n    }\n    g.fillStyle = \"rgba(0,0,0,.35)\"; g.beginPath(); g.arc(cx + 10, cy + 16, R + 6, 0, 7); g.fill();\n    g.fillStyle = \"#07120e\"; g.beginPath(); g.arc(cx, cy, R, 0, 7); g.fill();\n    g.lineWidth = 1;\n    for (var r = R * 0.38; r < R - 3; r += 4.2) { g.strokeStyle = rgba(C, 0.04 + rnd() * 0.07); g.beginPath(); g.arc(cx, cy, r, 0, 7); g.stroke(); }\n    var sheen = g.createConicGradient ? g.createConicGradient(0.6, cx, cy) : null;\n    if (sheen) {\n      sheen.addColorStop(0, \"rgba(255,255,255,0)\"); sheen.addColorStop(0.08, \"rgba(255,255,255,.2)\"); sheen.addColorStop(0.16, \"rgba(255,255,255,0)\");\n      sheen.addColorStop(0.5, \"rgba(255,255,255,0)\"); sheen.addColorStop(0.58, \"rgba(255,255,255,.2)\"); sheen.addColorStop(0.66, \"rgba(255,255,255,0)\"); sheen.addColorStop(1, \"rgba(255,255,255,0)\");\n      g.fillStyle = sheen; g.beginPath(); g.arc(cx, cy, R, 0, 7); g.arc(cx, cy, R * 0.38, 0, 7, true); g.fill(\"evenodd\");\n    }\n    g.strokeStyle = rgba(C, 0.55); g.lineWidth = 2; g.beginPath(); g.arc(cx, cy, R, 0, 7); g.stroke();\n    var lab = g.createRadialGradient(cx, cy, 6, cx, cy, R * 0.34); lab.addColorStop(0, mix(B, D, 0.12)); lab.addColorStop(1, mix(B, D, 0.38));\n    g.fillStyle = lab; g.beginPath(); g.arc(cx, cy, R * 0.34, 0, 7); g.fill();\n    g.strokeStyle = rgba(D, 0.7); g.lineWidth = 3;\n    g.beginPath(); g.arc(cx, cy, R * 0.26, 0, 7); g.stroke();\n    g.fillStyle = rgba(D, 0.8);\n    for (i = 0; i < 24; i++) { var ta = i / 24 * 6.2832; g.beginPath(); g.arc(cx + Math.cos(ta) * R * 0.3, cy + Math.sin(ta) * R * 0.3, 3, 0, 7); g.fill(); }\n    g.fillRect(cx - R * 0.12, cy + R * 0.12, R * 0.24, 5); g.fillRect(cx - R * 0.08, cy + R * 0.17, R * 0.16, 5);\n    g.fillStyle = \"#07120e\"; g.beginPath(); g.arc(cx, cy, 9, 0, 7); g.fill();\n    g.fillStyle = \"rgba(255,255,255,.03)\";\n    for (i = 0; i < 7000; i++) g.fillRect(rnd() * W, rnd() * H, 1.5, 1.5);\n    return c;\n  }\n\n  // built-in beat: kicks, snare and off-beat hats on a four beat bar, with a gentle moving pad underneath\n  var KICKS = [0, 1, 2, 2.75, 3], SNARES = [1, 3], HATS = [0.5, 1.5, 2.5, 3.5, 3.75];\n  function since(list, tb, beat, bar) {\n    var best = 99;\n    for (var i = 0; i < list.length; i++) { var d = (tb - list[i] * beat + bar) % bar; if (d < best) best = d; }\n    return best;\n  }\n  function synth(t) {\n    var beat = 60 / opts.bpm, bar = beat * 4, tb = t % bar;\n    var dk = since(KICKS, tb, beat, bar), ds = since(SNARES, tb, beat, bar), dh = since(HATS, tb, beat, bar);\n    var bass = Math.exp(-dk * 7.5), mid = Math.exp(-ds * 9), tre = Math.exp(-dh * 20);\n    lv.bass = bass; lv.mid = mid; lv.tre = tre; lv.k = dk;\n    for (var i = 0; i < 16; i++) {\n      var f = i / 15;\n      var v = bass * Math.pow(1 - f, 1.6) + mid * Math.exp(-Math.pow((f - 0.42) * 3.2, 2)) * 0.9 + tre * Math.pow(f, 1.2) * 0.85 + 0.07 * (Math.sin(t * 2.2 + i * 0.9) + 1) * (1 - f * 0.5);\n      lv.bins[i] = Math.min(1, v);\n    }\n  }\n  function listen(now) {\n    audio.an.getByteFrequencyData(audio.data);\n    var d = audio.data, i, j, s;\n    function avg(a, b) { var t = 0; for (var q = a; q <= b; q++) t += d[q]; return t / (b - a + 1) / 255; }\n    var bass = avg(1, 3), mid = avg(4, 20), tre = avg(21, 70);\n    peak = Math.max(peak * 0.997, bass, mid, tre, 0.12);\n    bass = Math.min(1, bass / peak); mid = Math.min(1, mid / peak); tre = Math.min(1, tre / peak);\n    if (bass > 0.55 && bass > prevBass * 1.12 && now - lastKick > 220) lastKick = now;\n    prevBass = bass * 0.5 + prevBass * 0.5;\n    lv.bass = bass; lv.mid = mid; lv.tre = tre; lv.k = (now - lastKick) / 1000;\n    for (i = 0; i < 16; i++) {\n      var a = Math.round(Math.pow(i / 16, 1.7) * 90) + 1, b = Math.max(a, Math.round(Math.pow((i + 1) / 16, 1.7) * 90) + 1);\n      s = 0; for (j = a; j <= b; j++) s += d[j]; lv.bins[i] = Math.min(1, s / (b - a + 1) / 255 / peak);\n    }\n  }\n\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    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return false;\n    gl.useProgram(prog);\n    var b = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, b);\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    [\"uT\", \"uTime\", \"uBass\", \"uMid\", \"uTre\", \"uK\", \"uI\", \"uAsp\", \"uS\"].forEach(function (k) { u[k] = gl.getUniformLocation(prog, k); });\n    tex = gl.createTexture(); gl.uniform1i(u.uT, 0);\n    return true;\n  }\n  function upload() {\n    if (!gl || !tex) return;\n    gl.bindTexture(gl.TEXTURE_2D, tex);\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, art);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n  }\n  function size() {\n    var dpr = Math.min(window.devicePixelRatio || 1, 1.5);\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; if (gl) gl.viewport(0, 0, w, h); }\n  }\n  function cover() { var a = canvas.width / canvas.height, i = art.width / art.height; return a > i ? [1, i / a] : [a / i, 1]; }\n  function draw(t, still) {\n    size();\n    var s = cover();\n    if (gl) {\n      gl.uniform1f(u.uTime, t); gl.uniform1f(u.uBass, still ? 0 : lv.bass); gl.uniform1f(u.uMid, still ? 0 : lv.mid); gl.uniform1f(u.uTre, still ? 0 : lv.tre);\n      gl.uniform1f(u.uK, still ? 9 : lv.k); gl.uniform1f(u.uI, still ? 0 : opts.intensity); gl.uniform1f(u.uAsp, canvas.width / canvas.height); gl.uniform2f(u.uS, s[0], s[1]);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    } else if (ctx2) {\n      var sw = art.width * s[0], sh2 = art.height * s[1];\n      ctx2.drawImage(art, (art.width - sw) / 2, (art.height - sh2) / 2, sw, sh2, 0, 0, canvas.width, canvas.height);\n      canvas.style.transform = still ? \"none\" : \"scale(\" + (1 + lv.bass * 0.05 * opts.intensity).toFixed(4) + \")\";\n    }\n  }\n  function paintBars(still) {\n    for (var i = 0; i < 16; i++) bars[i].style.transform = \"scaleY(\" + (still ? 0.08 : Math.max(0.08, lv.bins[i])).toFixed(3) + \")\";\n  }\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    if (!visible || document.hidden) return;\n    if (source === \"mic\" && audio) listen(now); else synth((now - t0) / 1000);\n    draw((now - t0) / 1000, false); paintBars(false);\n  }\n  function say(msg) { statusEl.textContent = msg; }\n  function stopMic() {\n    micToken++;\n    if (audio) { try { audio.stream.getTracks().forEach(function (t) { t.stop(); }); } catch (e) {} try { audio.ctx.close(); } catch (e2) {} audio = null; }\n    source = \"synth\"; micBtn.setAttribute(\"aria-pressed\", \"false\");\n  }\n  function startMic() {\n    if (reduce || destroyed) return;\n    var md = navigator.mediaDevices, AC = window.AudioContext || window.webkitAudioContext;\n    if (!md || !md.getUserMedia || !AC) { opts.mic = 0; say(\"Microphone not available here. Using the built-in beat.\"); return; }\n    var token = ++micToken; say(\"Waiting for microphone permission...\");\n    md.getUserMedia({ audio: true, video: false }).then(function (stream) {\n      if (token !== micToken || destroyed) { stream.getTracks().forEach(function (t) { t.stop(); }); return; }\n      var ctx = new AC(), an = ctx.createAnalyser(); an.fftSize = 256; an.smoothingTimeConstant = 0.6;\n      ctx.createMediaStreamSource(stream).connect(an); // not connected to the speakers, so no feedback\n      if (ctx.state === \"suspended\" && ctx.resume) ctx.resume();\n      audio = { stream: stream, ctx: ctx, an: an, data: new Uint8Array(an.frequencyBinCount) };\n      peak = 0.2; lastKick = performance.now(); source = \"mic\";\n      micBtn.setAttribute(\"aria-pressed\", \"true\"); micBtn.textContent = \"Use built-in beat\"; say(\"Listening to your microphone. Nothing is recorded or sent.\");\n    }).catch(function () {\n      if (token !== micToken) return;\n      opts.mic = 0; source = \"synth\"; micBtn.setAttribute(\"aria-pressed\", \"false\"); micBtn.textContent = \"Use microphone\";\n      say(\"Microphone blocked or unavailable. Using the built-in beat.\");\n    });\n  }\n  function applyMic() {\n    if (+opts.mic === 1) { if (source !== \"mic\" && !audio) startMic(); }\n    else if (source === \"mic\" || audio) { stopMic(); micBtn.textContent = \"Use microphone\"; say(\"Using the built-in beat.\"); }\n  }\n  function onMicClick() {\n    opts.mic = (+opts.mic === 1) ? 0 : 1;\n    applyMic();\n  }\n  function update(partial) {\n    var prev = opts;\n    opts = Object.assign({ bpm: 110, intensity: 1, mic: 0, colorA: \"#005236\", colorB: \"#e6ff55\" }, opts, partial || {});\n    wrap.style.setProperty(\"--ef-ap-accent\", opts.colorB);\n    if (!art || prev.colorA !== opts.colorA || prev.colorB !== opts.colorB) { art = makeArt(); upload(); }\n    if (destroyed) return;\n    if (partial && \"mic\" in partial) applyMic();\n    if (reduce) { draw(0, true); paintBars(true); }\n  }\n\n  gl = canvas.getContext(\"webgl\", { antialias: false, alpha: false, powerPreference: \"low-power\" });\n  var ok = !!gl && setup();\n  if (!ok) {\n    if (gl) { var c2 = canvas.cloneNode(false); canvas.parentNode.replaceChild(c2, canvas); canvas = c2; gl = null; }\n    ctx2 = canvas.getContext(\"2d\");\n  }\n  for (var i = 0; i < 16; i++) { var b = document.createElement(\"i\"); barsEl.appendChild(b); bars.push(b); }\n  // a mic value at mount time is ignored: the microphone starts only after a click or a later update\n  update(Object.assign({}, o || {}, { mic: 0 }));\n  opts.mic = 0;\n  micBtn.addEventListener(\"click\", onMicClick);\n  if (reduce) {\n    micBtn.disabled = true; say(\"Reduced motion is on, so the pulse is paused.\");\n    ro = \"ResizeObserver\" in window ? new ResizeObserver(function () { if (!destroyed) { draw(0, true); } }) : null;\n    if (ro) ro.observe(wrap);\n  } else {\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\n    raf = requestAnimationFrame(loop);\n  }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf); stopMic();\n      micBtn.removeEventListener(\"click\", onMicClick);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n      if (gl) { var ext = gl.getExtension(\"WEBGL_lose_context\"); if (tex) gl.deleteTexture(tex); if (prog) gl.deleteProgram(prog); if (ext) ext.loseContext(); }\n    }\n  };\n}"
  }
}