{
  "id": "scroll-camera-landscape",
  "kind": "element",
  "title": "Scroll camera landscape",
  "summary": "A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.",
  "url": "https://enrichr.dev/elements/scroll-camera-landscape.html",
  "section": "hero",
  "techniques": [
    "webgl",
    "scroll-driven"
  ],
  "stack": [
    "Vanilla JS",
    "WebGL 2"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "cinematic",
    "bold"
  ],
  "intents": [
    "scroll controlled 3d camera",
    "mountain landscape hero",
    "cinematic scroll 3d",
    "low poly terrain",
    "fly through scene on scroll"
  ],
  "status": "tested",
  "params": [
    {
      "key": "height",
      "label": "Mountain height",
      "type": "range",
      "min": 10,
      "max": 80,
      "step": 2,
      "value": 38
    },
    {
      "key": "travel",
      "label": "Distance flown over the scroll",
      "type": "range",
      "min": 100,
      "max": 1500,
      "step": 50,
      "value": 700
    },
    {
      "key": "time",
      "label": "Time of day (0 dawn, 0.5 noon, 1 dusk)",
      "type": "range",
      "min": 0,
      "max": 1,
      "step": 0.01,
      "value": 0.35
    },
    {
      "key": "shift",
      "label": "Time change over the scroll",
      "type": "range",
      "min": 0,
      "max": 1,
      "step": 0.05,
      "value": 0.5
    },
    {
      "key": "manual",
      "label": "Fixed progress % (0 follows scroll)",
      "type": "range",
      "min": 0,
      "max": 100,
      "step": 5,
      "value": 0
    },
    {
      "key": "colorLow",
      "label": "Valley colour",
      "type": "color",
      "value": "#3a6b50"
    },
    {
      "key": "colorHigh",
      "label": "Peak colour",
      "type": "color",
      "value": "#e8efe0"
    },
    {
      "key": "sky",
      "label": "Daytime sky",
      "type": "color",
      "value": "#8fc7ff"
    }
  ],
  "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 \"Scroll camera landscape\" element to this project.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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/scroll-camera-landscape.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 \"Scroll camera landscape\" 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 \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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 \"Scroll camera landscape\" element to this codebase.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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-scroll-camera-landscape.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Scroll camera landscape 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 \"Scroll camera landscape\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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- scroll-camera-landscape.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 \"./scroll-camera-landscape\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollCameraLandscape(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 \"Scroll camera landscape\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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- scroll-camera-landscape.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/ScrollCameraLandscape.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./scroll-camera-landscape\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollCameraLandscape(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 \"Scroll camera landscape\" element.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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), scroll-camera-landscape.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 \"Scroll camera landscape\" element. No packages, no server code.\n\nThis is the \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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 scroll-camera-landscape.js and then main.js), style.css (the CSS below), scroll-camera-landscape.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 \"Scroll camera landscape\" 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 \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.json\n\nWhat it does: The terrain is a flat grid of triangles whose heights are computed in the vertex shader from a layered, ridged sine function of the world position, so there are no models or textures to load. The grid is recentred on the camera each frame in whole cells, which makes the landscape endless without popping. The camera follows a winding path down a carved valley, with scroll progress as the distance along it. The same height function runs in JavaScript to keep the camera above the ground. Flat shading comes from screen-space derivatives, and fog fades the distance into the sky colour. The sun angle moves with the time of day, changing light and sky.\nAccessibility: The canvas is a labelled image and decorative. With reduced motion the camera stays at its start and the scene does not respond to scroll. If WebGL 2 is unavailable the container keeps a plain gradient in the sky and valley colours.\n\nTunable settings:\n- Mountain height: range 10 to 80, step 2, default 38\n- Distance flown over the scroll: range 100 to 1500, step 50, default 700\n- Time of day (0 dawn, 0.5 noon, 1 dusk): range 0 to 1, step 0.01, default 0.35\n- Time change over the scroll: range 0 to 1, step 0.05, default 0.5\n- Fixed progress % (0 follows scroll): range 0 to 100, step 5, default 0\n- Valley colour: color, default #3a6b50\n- Peak colour: color, default #e8efe0\n- Daytime sky: color, default #8fc7ff\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/scroll-camera-landscape.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 \"Scroll camera landscape\" 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 \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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 ScrollCameraLandscape.\n2. Paste the JavaScript below into a separate code file named scroll-camera-landscape.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 \"./scroll-camera-landscape\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function ScrollCameraLandscape(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(ScrollCameraLandscape, {\n  height: { type: ControlType.Number, title: \"Mountain height\", min: 10, max: 80, step: 2, defaultValue: 38 },\n  travel: { type: ControlType.Number, title: \"Distance flown over the scroll\", min: 100, max: 1500, step: 50, defaultValue: 700 },\n  time: { type: ControlType.Number, title: \"Time of day\", min: 0, max: 1, step: 0.01, defaultValue: 0.35 },\n  shift: { type: ControlType.Number, title: \"Time change over the scroll\", min: 0, max: 1, step: 0.05, defaultValue: 0.5 },\n  manual: { type: ControlType.Number, title: \"Fixed progress %\", min: 0, max: 100, step: 5, defaultValue: 0 },\n  colorLow: { type: ControlType.Color, title: \"Valley colour\", defaultValue: \"#3a6b50\" },\n  colorHigh: { type: ControlType.Color, title: \"Peak colour\", defaultValue: \"#e8efe0\" },\n  sky: { type: ControlType.Color, title: \"Daytime sky\", defaultValue: \"#8fc7ff\" },\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 \"Scroll camera landscape\" 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 \"Scroll camera landscape\" element from the Enrichr Library: A procedural low-poly mountain range that the camera flies through as you scroll, with a sun that moves from dawn to dusk.\nPage: https://enrichr.dev/elements/scroll-camera-landscape.html\nMachine-readable spec: https://enrichr.dev/elements/scroll-camera-landscape.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-scroll-camera-landscape\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-scroll-camera-landscape\"), { ...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 a labelled image and decorative. With reduced motion the camera stays at its start and the scene does not respond to scroll. If WebGL 2 is unavailable the container keeps a plain gradient in the sky and valley colours.",
  "performance": "About 72,000 indices drawn once per update; it only redraws when you scroll, resize or change a control, and not at all while off screen. The pixel ratio is capped at 1.5. Test on a mid-range phone and reduce the grid size in the source if needed.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-land\"><canvas class=\"ef-land__c\" role=\"img\" aria-label=\"A low-poly mountain landscape the camera flies through as the page scrolls\"></canvas></div>",
    "css": ".ef-land { position: absolute; inset: 0; overflow: hidden; background: linear-gradient(180deg, var(--ef-sky, #8fc7ff), var(--ef-low, #1f3b2d)); }\r\n.ef-land__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }",
    "js": "// Scroll camera landscape: a procedural low-poly mountain range with a camera that flies down a valley as the page scrolls,\r\n// and a sun that moves from dawn to dusk. No models or textures: the terrain is a height function evaluated on the GPU, the\r\n// same function runs in JavaScript to keep the camera above the ground. Needs WebGL 2; without it the CSS gradient stays.\r\n// Put it in a positioned parent with a height; the element fills it.\r\n// mount(root, { height (terrain), travel (distance flown), time (0 dawn - 0.5 noon - 1 dusk), shift (time change over the scroll),\r\n//               manual (0 = follow scroll, 1-100 = fixed %), colorLow, colorHigh, sky })\r\nfunction mount(root, o) {\r\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\r\n  var wrap = root.querySelector(\".ef-land\");\r\n  var canvas = root.querySelector(\".ef-land__c\");\r\n  var gl = canvas.getContext(\"webgl2\", { antialias: true, alpha: false, powerPreference: \"low-power\" });\r\n  var opts = {}, raf = 0, visible = true, io = null, prog, u = {}, vao, count = 0;\r\n  var N = 110, CELL = 3.2;\r\n\r\n  var VS = [\"#version 300 es\", \"in vec2 aXZ;uniform mat4 uVP;uniform vec2 uSnap;uniform float uAmp;out vec3 vW;\",\r\n    \"float r(float a,float b){return 1.-abs(sin(a)*cos(b));}\",\r\n    \"float hf(vec2 p){float x=p.x,z=p.y;float h=.55*r(x*.020+.6*sin(z*.011),z*.017)+.30*r(x*.047+1.3,z*.051+.4)+.15*r(x*.11,z*.10+2.);\",\r\n    \"float c=smoothstep(0.,34.,abs(x-14.*sin(z*.012)));return uAmp*h*mix(.2,1.,c);}\",\r\n    \"void main(){vec2 w=aXZ+uSnap;vW=vec3(w.x,hf(w),w.y);gl_Position=uVP*vec4(vW,1.);}\"].join(\"\\n\");\r\n  var FS = [\"#version 300 es\", \"precision highp float;in vec3 vW;out vec4 o;\",\r\n    \"uniform vec3 uLo,uHi,uSky,uSun,uCam;uniform float uAmp,uLight,uFog;\",\r\n    \"void main(){vec3 n=normalize(cross(dFdx(vW),dFdy(vW)));if(n.y<0.)n=-n;float l=max(dot(n,normalize(uSun)),0.);\",\r\n    \"float t=clamp(vW.y/uAmp,0.,1.);vec3 c=mix(uLo,uHi,smoothstep(.15,.85,t))*(.4+.9*l*uLight);\",\r\n    \"float d=distance(vW,uCam);float f=1.-exp(-pow(d/uFog,2.));o=vec4(mix(c,uSky,clamp(f,0.,1.)),1.);}\"].join(\"\\n\");\r\n\r\n  // the same height function as the vertex shader, so the camera stays above the ground\r\n  function rr(a, b) { return 1 - Math.abs(Math.sin(a) * Math.cos(b)); }\r\n  function sm(e0, e1, x) { var t = Math.min(1, Math.max(0, (x - e0) / (e1 - e0))); return t * t * (3 - 2 * t); }\r\n  function pathX(z) { return 14 * Math.sin(z * 0.012); }\r\n  function hf(x, z, amp) {\r\n    var h = 0.55 * rr(x * 0.020 + 0.6 * Math.sin(z * 0.011), z * 0.017) + 0.30 * rr(x * 0.047 + 1.3, z * 0.051 + 0.4) + 0.15 * rr(x * 0.11, z * 0.10 + 2.0);\r\n    return amp * h * (0.2 + 0.8 * sm(0, 34, Math.abs(x - pathX(z))));\r\n  }\r\n  function persp(fovy, asp, n, f) { var t = 1 / Math.tan(fovy / 2), nf = 1 / (n - f); return new Float32Array([t / asp, 0, 0, 0, 0, t, 0, 0, 0, 0, (f + n) * nf, -1, 0, 0, 2 * f * n * nf, 0]); }\r\n  function look(e, c) {\r\n    var zx = e[0] - c[0], zy = e[1] - c[1], zz = e[2] - c[2], l = Math.hypot(zx, zy, zz);\r\n    zx /= l; zy /= l; zz /= l;\r\n    var xx = zz, xz = -zx; l = Math.hypot(xx, xz); xx /= l; xz /= l;\r\n    var yx = zy * xz, yy = zz * xx - zx * xz, yz = -zy * xx;\r\n    return new Float32Array([xx, yx, zx, 0, 0, yy, zy, 0, xz, yz, zz, 0, -(xx * e[0] + xz * e[2]), -(yx * e[0] + yy * e[1] + yz * e[2]), -(zx * e[0] + zy * e[1] + zz * e[2]), 1]);\r\n  }\r\n  function mul(a, b) { var out = new Float32Array(16); for (var i = 0; i < 4; i++) for (var j = 0; j < 4; j++) { var s = 0; for (var k = 0; k < 4; k++) s += a[k * 4 + j] * b[i * 4 + k]; out[i * 4 + j] = s; } return out; }\r\n  function rgb(hex) { var m = /^#?([0-9a-f]{6})$/i.exec(hex || \"\"); var v = parseInt(m ? m[1] : \"808080\", 16); return [(v >> 16) / 255, ((v >> 8) & 255) / 255, (v & 255) / 255]; }\r\n\r\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; }\r\n  function setup() {\r\n    var v = sh(gl.VERTEX_SHADER, VS), f = sh(gl.FRAGMENT_SHADER, FS);\r\n    if (!v || !f) { prog = null; return false; }\r\n    prog = gl.createProgram(); gl.attachShader(prog, v); gl.attachShader(prog, f); gl.linkProgram(prog);\r\n    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) { prog = null; return false; }\r\n    gl.useProgram(prog);\r\n    var verts = new Float32Array((N + 1) * (N + 1) * 2), k = 0;\r\n    for (var j = 0; j <= N; j++) for (var i = 0; i <= N; i++) { verts[k++] = (i - N / 2) * CELL; verts[k++] = (j - N / 2) * CELL; }\r\n    var idx = new Uint32Array(N * N * 6); k = 0;\r\n    for (var y = 0; y < N; y++) for (var x = 0; x < N; x++) { var a = y * (N + 1) + x, b = a + 1, c = a + N + 1, d = c + 1; idx[k++] = a; idx[k++] = c; idx[k++] = b; idx[k++] = b; idx[k++] = c; idx[k++] = d; }\r\n    count = idx.length;\r\n    vao = gl.createVertexArray(); gl.bindVertexArray(vao);\r\n    var vb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vb); gl.bufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW);\r\n    var loc = gl.getAttribLocation(prog, \"aXZ\"); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\r\n    var ib = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, idx, gl.STATIC_DRAW);\r\n    [\"uVP\", \"uSnap\", \"uAmp\", \"uLo\", \"uHi\", \"uSky\", \"uSun\", \"uCam\", \"uLight\", \"uFog\"].forEach(function (n) { u[n] = gl.getUniformLocation(prog, n); });\r\n    gl.enable(gl.DEPTH_TEST);\r\n    return true;\r\n  }\r\n  function progress() {\r\n    if (reduce) return 0;\r\n    if (opts.manual > 0) return opts.manual / 100;\r\n    var r = wrap.getBoundingClientRect(), vh = window.innerHeight || 800;\r\n    return Math.min(1, Math.max(0, (vh - r.top) / (vh + r.height)));\r\n  }\r\n  function render() {\r\n    raf = 0;\r\n    if (!visible || !prog) return;\r\n    var dpr = Math.min(window.devicePixelRatio || 1, 1.5);\r\n    var w = Math.max(1, Math.round(wrap.clientWidth * dpr)), h = Math.max(1, Math.round(wrap.clientHeight * dpr));\r\n    if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; }\r\n    gl.viewport(0, 0, w, h);\r\n    var p = progress(), amp = opts.height;\r\n    var z = -opts.travel * p, x = pathX(z);\r\n    var ey = hf(x, z, amp) + 9, lz = z - 45, lx = pathX(lz), ly = hf(lx, lz, amp) + 9;\r\n    var VP = mul(persp(1.0, w / h, 0.5, 500), look([x, ey, z], [lx, ly, lz]));\r\n    var t = Math.min(1, Math.max(0, opts.time + opts.shift * p)), e = Math.sin(t * Math.PI), k = sm(0.05, 0.6, e);\r\n    var day = rgb(opts.sky), dusk = [0.95, 0.5, 0.35], sky = [0, 1, 2].map(function (i) { return dusk[i] * 0.55 * (1 - k) + day[i] * k; });\r\n    gl.clearColor(sky[0], sky[1], sky[2], 1);\r\n    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);\r\n    gl.uniformMatrix4fv(u.uVP, false, VP);\r\n    gl.uniform2f(u.uSnap, Math.round(x / CELL) * CELL, Math.round(z / CELL) * CELL);\r\n    gl.uniform1f(u.uAmp, amp);\r\n    gl.uniform3fv(u.uLo, rgb(opts.colorLow)); gl.uniform3fv(u.uHi, rgb(opts.colorHigh)); gl.uniform3fv(u.uSky, sky);\r\n    gl.uniform3f(u.uSun, Math.cos(t * Math.PI) * 0.8, e * 0.9 + 0.1, -0.5);\r\n    gl.uniform3f(u.uCam, x, ey, z);\r\n    gl.uniform1f(u.uLight, 0.3 + 0.7 * e); gl.uniform1f(u.uFog, 260);\r\n    gl.bindVertexArray(vao);\r\n    gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_INT, 0);\r\n  }\r\n  function schedule() { if (!raf) raf = requestAnimationFrame(render); }\r\n  function update(next) {\r\n    opts = Object.assign({ height: 38, travel: 700, time: 0.35, shift: 0.5, manual: 0, colorLow: \"#3a6b50\", colorHigh: \"#e8efe0\", sky: \"#8fc7ff\" }, opts, next || {});\r\n    wrap.style.setProperty(\"--ef-sky\", opts.sky);\r\n    wrap.style.setProperty(\"--ef-low\", opts.colorLow);\r\n    schedule();\r\n  }\r\n  var ok = gl && setup();\r\n  update(o);\r\n  if (!ok) { canvas.style.display = \"none\"; return { update: update, destroy: function () {} }; }\r\n  if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; if (visible) schedule(); }); io.observe(wrap); }\r\n  window.addEventListener(\"resize\", schedule);\r\n  if (!reduce) window.addEventListener(\"scroll\", schedule, { passive: true });\r\n  return { update: update, destroy: function () { cancelAnimationFrame(raf); if (io) io.disconnect(); window.removeEventListener(\"scroll\", schedule); window.removeEventListener(\"resize\", schedule); } };\r\n}"
  }
}