176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Abstract Geometric Motion to the guided-steps page
matin43b024a1570e
diff --git a/animations/07-ambient-background/abstract-geometric-motion/README.md b/animations/07-ambient-background/abstract-geometric-motion/README.mdindex 3991197a..6d650b8f 100644--- a/animations/07-ambient-background/abstract-geometric-motion/README.md+++ b/animations/07-ambient-background/abstract-geometric-motion/README.md@@ -1,7 +1,7 @@# Abstract Geometric Motion## What it is-Abstract geometric motion is a continuous, looping animation of pure geometric forms — rotating polygons, expanding rings, sliding bars, flowing lines — that exists purely to be watched. There is no narrative, no story, no user interaction required. The design intent is the same as a screensaver, a music visualizer, or an abstract painting: visually satisfying, optionally hypnotic, never demanding. Watch for 30 seconds and the mind quiets.+Abstract geometric motion is an endless loop of simple shapes that exists just to be watched: polygons slowly turning, rings spreading out from the center, slanted bars sliding by, or wavy lines with color flowing along them. There is no story and nothing to click. Like a screensaver or a music visualizer, it is meant to stay calm and pleasant to look at for a long time.## When to use it- "Now playing" and music player backgrounds where the visual should pulse with the content@@ -10,13 +10,13 @@ Abstract geometric motion is a continuous, looping animation of pure geometric f- Empty states and loading screens where the environment should feel designed, not blank## How it works-All four presets run on a shared `requestAnimationFrame` loop with a global time counter `t`. Each preset renders to a `<canvas>` element.+All four presets run on a shared `requestAnimationFrame` loop with a global time counter `t`. Each 60th of a second that passes adds `speed * 0.01` to it and grows every ring by `speed * 2` pixels, however many frames that takes, so a 120 Hz screen or a slow frame does not change the speed. Each preset renders to a `<canvas>` element.**Rotating polygons** — regular polygons with increasing vertex counts, each rotating at a slightly different rate:```jsfunction drawPolygons(t) {- for (let i = 0; i < complexity; i++) {+ for (let i = 0; i < shapeCount; i++) {const sides = 3 + (i % 5); // 3 to 7 sidesconst radius = 30 + i * 20;const rotation = t * (0.2 + i * 0.08) + (i % 2 === 0 ? 0 : Math.PI);@@ -27,7 +27,7 @@ function drawPolygons(t) {ctx.lineTo(cx + Math.cos(a) * radius, cy + Math.sin(a) * radius);}ctx.strokeStyle = palette(i, 0.5 + 0.3 * Math.sin(t * 0.5 + i));- ctx.lineWidth = 0.8;+ ctx.lineWidth = lineWidth * (1 + i * 0.1); // 0.8, or 1.5 with Thicker linesctx.stroke();}}@@ -41,7 +41,7 @@ if (t - lastSpawn >= 0.5) { lastSpawn = t; rings.push({ r: 0, color: randomColor// Update and draw each ringrings.forEach(ring => {- ring.r += speed;+ ring.r += speed * 2;const life = 1 - ring.r / Math.max(W, H);ctx.strokeStyle = `rgba(..., ${life * 0.6})`;ctx.arc(cx, cy, ring.r, 0, Math.PI * 2);@@ -50,11 +50,13 @@ rings.forEach(ring => {rings = rings.filter(r => r.r < Math.max(W, H));```+Choosing Rings starts with six rings already spread across the stage, so the pattern shows at once instead of growing from an empty stage.+**Color-flow lines** — sine-wave curves with animated `lineDashOffset` so colors appear to travel along the path:```jsctx.setLineDash([40, 60]);-ctx.lineDashOffset = -t * 30 * speed + i * 20; // advances per frame+ctx.lineDashOffset = -dashPhase + i * 20; // dashPhase grows by 30 * speed each time t grows by 1ctx.strokeStyle = palette(i, opacity);ctx.beginPath();// ... draw sine wave path ...@@ -62,12 +64,16 @@ ctx.stroke();ctx.setLineDash([]);```+**The sliding bars and the flowing dashes** keep their own distance counters, `barX` and `dashPhase`, which grow by `40 * speed` and `30 * speed` each time `t` grows by 1. Adding to a counter, rather than multiplying `t` by the speed, means changing the speed never makes the bars or the dashes jump.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Speed | 0.6 | Lower = meditative; higher = energetic. Keep below 1.0 for ambient. |-| Complexity | 6 | Number of shapes/lines. More = busier; fewer = minimal. |-| Palette | Cool | Color family. All presets respect the same palette variable. |+| Pattern | Polygons | Turning polygons, rings spreading from the center, sliding bars, or wavy lines with flowing color |+| Speed | Normal | How fast everything moves: slow is 0.35, normal 0.6 and fast 1; keep it below 1 behind content |+| Number of shapes | Medium | How many polygons, bars or lines: few is 3, medium 6 and many 10 (the Lines pattern draws twice as many) |+| Colors | Cool | Cool blues, warm ambers, bright neon or grays |+| Thicker lines | off | Draws the lines 1.5px wide instead of 0.8px, so the shapes stand out more |## Production notes- **Canvas vs SVG vs CSS**: canvas is ideal for complex animated geometry that changes every frame. SVG SMIL animation works for a few elements but becomes expensive with many independently animated paths. CSS is impractical for runtime-generated geometry.@@ -78,6 +84,6 @@ ctx.setLineDash([]);- **Three.js equivalent**: `LineSegments`, `MeshLine`, and custom `ShaderMaterial` can recreate all four presets in a 3D context with camera movement adding the third dimension.## See also-- [Ambient Ripple](../ambient-ripple/) — the "rings" preset abstracted as a standalone ambient effect-- [WebGL Shader Animation](../../06-3d-advanced/webgl-shader-animation/) — GPU-powered shader patterns; more complex but higher visual ceiling-- [Noise-Based Motion](../../06-3d-advanced/noise-based-motion/) — organic, non-geometric motion using Perlin/Simplex noise+- [Ambient Ripple Effect](../ambient-ripple/) — rings spreading from a few spots, on their own+- [WebGL Shader Animation](../../06-3d-advanced/webgl-shader-animation/) — patterns drawn by the graphics card+- [Noise-Based Motion](../../06-3d-advanced/noise-based-motion/) — smooth, natural-looking random motiondiff --git a/animations/07-ambient-background/abstract-geometric-motion/index.html b/animations/07-ambient-background/abstract-geometric-motion/index.htmlindex 59117954..0937240f 100644--- a/animations/07-ambient-background/abstract-geometric-motion/index.html+++ b/animations/07-ambient-background/abstract-geometric-motion/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Abstract Geometric Motion — Animation Handbook</title>- <meta name="description" content="Four hypnotic loops — polygons, rings, bars, color lines. Satisfying to watch, never demanding.">+ <meta name="description" content="Shapes turn, spread and flow in a calm, endless pattern. Best for music players."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/abstract-geometric-motion/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,238 +12,315 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Abstract Geometric Motion — Animation Handbook">- <meta property="og:description" content="Four hypnotic loops — polygons, rings, bars, color lines. Satisfying to watch, never demanding.">+ <meta property="og:description" content="Shapes turn, spread and flow in a calm, endless pattern. Best for music players."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/abstract-geometric-motion/"><meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:title" content="Abstract Geometric Motion — Animation Handbook">- <meta name="twitter:description" content="Four hypnotic loops — polygons, rings, bars, color lines. Satisfying to watch, never demanding.">+ <meta name="twitter:description" content="Shapes turn, spread and flow in a calm, endless pattern. Best for music players."><meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Abstract Geometric Motion", "name": "Abstract Geometric Motion", "description": "Four hypnotic loops — polygons, rings, bars, color lines. Satisfying to watch, never demanding.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/abstract-geometric-motion/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Abstract Geometric Motion"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Abstract Geometric Motion", "name": "Abstract Geometric Motion", "description": "Shapes turn, spread and flow in a calm, endless pattern. Best for music players.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/abstract-geometric-motion/", "inLanguage": "en", "articleSection": "Ambient & Background", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Ambient & Background, Abstract Geometric Motion"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ffce5a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}+ :root{--ui-accent:#ffce5a}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}- header{margin-bottom:20px}- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;overflow:hidden;position:relative}+ .stage{position:relative;overflow:hidden;background:#020408}canvas{display:block;width:100%;height:100%}- .preset-tabs{position:absolute;top:8px;left:8px;display:flex;gap:4px;z-index:5}- .ptab{background:rgba(17,17,20,.8);border:1px solid var(--ui-border);color:var(--ui-muted);font-family:var(--mono);font-size:9px;padding:5px 10px;border-radius:4px;cursor:pointer;min-height:36px;letter-spacing:.5px}- .ptab.active{border-color:var(--ui-accent);color:var(--ui-accent)}- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}- .div{height:1px;background:var(--ui-border)}- .sr{display:flex;align-items:center;gap:6px;font-size:10px}- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}- .sv{width:40px;text-align:right;color:var(--ui-text)}- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;border-radius:4px;cursor:pointer;width:100%}- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column;align-items:stretch}.stage{flex:none;width:100%}.ptab{min-height:44px}aside{width:100%}:root{--stage-h:420px}}</style>-<style id="ah-inject">-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}-body{padding-top:46px}-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}-.ah-home{color:var(--ah-ink);font-weight:600}-.ah-actions{display:flex;align-items:center;gap:2px}-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}-.ah-copied{color:var(--ah-accent)!important}-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}-@media print{.ah-bar{display:none}body{padding-top:0}}-</style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">+ <script src="../../../assets/js/demo-page.js?v=3" defer></script></head>-<body>-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../grid-dot-pattern-parallax/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../particle-constellation/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/07-ambient-background/abstract-geometric-motion/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Abstract Geometric Motion</h1>- <p>Four hypnotic loops — polygons, rings, bars, color lines. Satisfying to watch, never demanding.</p>-</header>-<div class="layout">- <div class="stage" id="stage">- <canvas id="cvs"></canvas>- <div class="preset-tabs" id="tabs">- <button class="ptab active" data-idx="0">Polygons</button>- <button class="ptab" data-idx="1">Rings</button>- <button class="ptab" data-idx="2">Bars</button>- <button class="ptab" data-idx="3">Lines</button>+<body class="hb" data-hb-kind="loop">+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../grid-dot-pattern-parallax/" rel="prev" aria-label="Previous: Grid / Dot Pattern Parallax"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Grid / Dot Pattern Parallax</span></a><a href="../particle-constellation/" rel="next" aria-label="Next: Particle Constellation"><span><span class="hb-dir">Next: </span>Particle Constellation</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">07.12 · Ambient & Background</p>+ <h1>Abstract Geometric Motion</h1>+ <p class="hb-lede">Shapes turn, spread and flow in a calm, endless pattern. Best for music players.</p>+ </header>++ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">1</span>+ <div><h2 id="hb-watch-title">Watch it</h2><p>It moves by itself. Pause it to look closely, or turn on slow motion to see each part of the movement.</p></div>+ </div>+ <div class="stage">+ <canvas id="cvs" aria-hidden="true"></canvas>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>+ </div>+ </section>++ <section class="hb-step hb-try" aria-labelledby="hb-try-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">2</span>+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and see the difference as it moves.</p></div></div>- </div>- <aside>- <p class="note">Abstract geometric motion is the descendant of screensaver art. Visually satisfying, never demanding interaction. Watch for 30 seconds — the mind quiets.</p>- <div class="lbl">Speed</div>- <div class="sr"><input type="range" id="spd-sl" min="1" max="20" value="6" step="1"><span class="sv" id="spd-v">0.6</span></div>- <div class="lbl">Complexity</div>- <div class="sr"><input type="range" id="cx-sl" min="2" max="12" value="6" step="1"><span class="sv" id="cx-v">6</span></div>- <div class="lbl">Palette</div>- <select id="pal-sel">- <option value="cool" selected>Cool blue</option>- <option value="warm">Warm amber</option>- <option value="neon">Neon</option>- <option value="mono">Monochrome</option>- </select>- <div class="lbl">Background</div>- <select id="bg-sel">- <option value="#020408" selected>Near black</option>- <option value="#060a10">Dark blue</option>- <option value="#080510">Dark purple</option>- </select>- <label class="tog"><input type="checkbox" id="contrast-tog"><span>High contrast</span></label>- <div class="div"></div>- <button class="rst" id="pause-btn">⏸ Pause</button>- </aside>-</div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="pat-lbl">Pattern</p>+ <div class="seg" id="pat-seg" role="group" aria-labelledby="pat-lbl">+ <button type="button" data-idx="0" class="on" aria-pressed="true">Polygons</button>+ <button type="button" data-idx="1" aria-pressed="false">Rings</button>+ <button type="button" data-idx="2" aria-pressed="false">Bars</button>+ <button type="button" data-idx="3" aria-pressed="false">Lines</button>+ </div>+ <p class="hb-hint">Four patterns, each an endless loop.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-spd="0.35" aria-pressed="false">Slow</button>+ <button type="button" data-spd="0.6" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-spd="1" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">Slow feels calm; keep it slow behind content.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="num-lbl">Number of shapes</p>+ <div class="seg" id="num-seg" role="group" aria-labelledby="num-lbl">+ <button type="button" data-n="3" aria-pressed="false">Few</button>+ <button type="button" data-n="6" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-n="10" aria-pressed="false">Many</button>+ </div>+ <p class="hb-hint">More shapes make a busier pattern.</p>+ </div>+ </div>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="pal-lbl">Colors</p>+ <div class="seg" id="pal-seg" role="group" aria-labelledby="pal-lbl">+ <button type="button" data-pal="cool" class="on" aria-pressed="true">Cool</button>+ <button type="button" data-pal="warm" aria-pressed="false">Warm</button>+ <button type="button" data-pal="neon" aria-pressed="false">Neon</button>+ <button type="button" data-pal="mono" aria-pressed="false">Gray</button>+ </div>+ <p class="hb-hint">The set of colors the shapes use.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Thicker lines</span><input class="hb-switch" type="checkbox" role="switch" id="thick-tog" autocomplete="off"></label>+ <p class="hb-hint">Bolder lines that stand out more.</p>+ </div>+ </div>+ </details>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add an abstract geometric animation to [the section or screen you want a calm moving background in]. Draw simple shapes on a canvas and keep them moving in an endless loop: polygons slowly turning around the center, rings spreading out and fading, slanted bars sliding across, or wavy lines with color flowing along them. Drive everything from one steadily growing time value, so the loop never restarts or jumps. Colors from one family keep it calm. If the visitor has reduced motion turned on, show one still frame. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Music and media players</li><li>Screensavers and kiosks</li><li>Loading screens</li><li>Art pages</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Forms</li><li>Long reading pages</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer><script>-const cvs=document.getElementById('cvs'),ctx=cvs.getContext('2d');-const stage=document.getElementById('stage');-let W,H,paused=false,raf=null,lastT=0,t=0;-let PRESET=0,SPD=0.6,CX=6,PAL='cool',BG='#020408',CONTRAST=false;-const RM=matchMedia('(prefers-reduced-motion:reduce)');--function resize(){- const dpr=Math.min(window.devicePixelRatio||1,2);- W=stage.clientWidth;H=stage.clientHeight;- cvs.width=Math.round(W*dpr);cvs.height=Math.round(H*dpr);- ctx.setTransform(dpr,0,0,dpr,0,0);- if(!raf)repaint(); // keep a frame on screen while paused / reduced-motion-}-window.addEventListener('resize',resize);--const PALETTES={- cool:c=>`hsla(${200+c*10},70%,65%,`,- warm:c=>`hsla(${30+c*8},80%,60%,`,- neon:c=>`hsla(${(c*60)%360},100%,65%,`,- mono:c=>`hsla(0,0%,${60+c*5}%,`-};--function col(c,a){return PALETTES[PAL](c)+a+')';}-function lineW(){return CONTRAST?1.5:.8;}--// PRESET 0: Rotating polygons-function drawPolygons(){- const cx=W/2,cy=H/2;- for(let i=0;i<CX;i++){- const n=3+i%5; // 3 to 7 sides- const r=30+i*20;- const rot=t*(0.2+i*.08)+(i%2===0?0:Math.PI);- ctx.beginPath();- for(let j=0;j<=n;j++){const a=j/n*Math.PI*2+rot;ctx.lineTo(cx+Math.cos(a)*r,cy+Math.sin(a)*r);}- ctx.strokeStyle=col(i,.5+Math.sin(t*.5+i)*.3);- ctx.lineWidth=lineW()*(1+i*.1);ctx.stroke();+ const cvs=document.getElementById('cvs'),ctx=cvs.getContext('2d');+ const stage=document.querySelector('.stage');+ const slowTog=document.getElementById('slow-tog');+ const BG='#020408';+ const FRAME=1000/60; // one step is what a 60 Hz frame adds, so a faster screen or a slow frame does not change the speed+ let W=0,H=0,raf=null,lastT=null,paused=false;+ let t=0; // the pattern's own time: it moves only while the loop runs+ let rings=[],ringT=0; // the rings on screen, and the time the last one was sent out+ let barX=0,dashPhase=0; // how far the bars and the dashes have travelled, so a Speed change never moves them+ let PRESET=0,SPD=0.6,CX=6,PAL='cool',CONTRAST=false;++ const PALETTES={+ cool:c=>`hsla(${200+c*10},70%,65%,`,+ warm:c=>`hsla(${30+c*8},80%,60%,`,+ neon:c=>`hsla(${(c*60)%360},100%,65%,`,+ mono:c=>`hsla(0,0%,${60+c*5}%,`+ };++ function col(c,a){return PALETTES[PAL](c)+a+')';}+ function lineW(){return CONTRAST?1.5:.8;}++ // PRESET 0: Rotating polygons+ function drawPolygons(){+ const cx=W/2,cy=H/2;+ for(let i=0;i<CX;i++){+ const n=3+i%5; // 3 to 7 sides+ const r=30+i*20;+ const rot=t*(0.2+i*.08)+(i%2===0?0:Math.PI);+ ctx.beginPath();+ for(let j=0;j<=n;j++){const a=j/n*Math.PI*2+rot;ctx.lineTo(cx+Math.cos(a)*r,cy+Math.sin(a)*r);}+ ctx.strokeStyle=col(i,.5+Math.sin(t*.5+i)*.3);+ ctx.lineWidth=lineW()*(1+i*.1);ctx.stroke();+ }}-}--// PRESET 1: Concentric expanding rings-let rings2=[],ringT=-1e9;-function updateRings(){- if(t-ringT>=.5){ringT=t;rings2.push({r:0,born:t,c:Math.floor(Math.random()*CX)});}- rings2=rings2.filter(r=>r.r<Math.max(W,H));- rings2.forEach(r=>{r.r+=SPD*2;});-}-function drawRings(){- const cx=W/2,cy=H/2;- rings2.forEach(r=>{- const life=1-r.r/Math.max(W,H);- ctx.beginPath();ctx.arc(cx,cy,r.r,0,Math.PI*2);- ctx.strokeStyle=col(r.c,life*.6);ctx.lineWidth=lineW()*(1+life);ctx.stroke();- });-}--// PRESET 2: Sliding bars-function drawBars(){- const count=CX;- for(let i=0;i<count;i++){- const x=(t*SPD*40+i*(W/count)*1.1)%W;- const barW=W/count*.5;- const op=.15+.1*Math.sin(t+i*.7);- ctx.fillStyle=col(i,op);- // Diagonal slant- ctx.save();ctx.translate(x,0);- ctx.beginPath();- ctx.moveTo(-barW*.2,0);ctx.lineTo(barW*.8,0);ctx.lineTo(barW*.6,H);ctx.lineTo(-barW*.4,H);ctx.closePath();- ctx.fill();ctx.restore();++ // PRESET 1: Concentric expanding rings+ function drawRings(){+ const cx=W/2,cy=H/2;+ rings.forEach(r=>{+ const life=1-r.r/Math.max(W,H);+ ctx.beginPath();ctx.arc(cx,cy,r.r,0,Math.PI*2);+ ctx.strokeStyle=col(r.c,life*.6);ctx.lineWidth=lineW()*(1+life);ctx.stroke();+ });}-}--// PRESET 3: Color-flow lines-function drawLines(){- const count=CX*2;- for(let i=0;i<count;i++){- const y=H*(i+.5)/count;- const amp=15+i*3;- const phase=i*.4+t*.8;- ctx.beginPath();- for(let x=0;x<=W;x+=4){- const py=y+Math.sin(x/80+phase)*amp+Math.cos(x/120+phase*.7)*amp*.5;- x===0?ctx.moveTo(x,py):ctx.lineTo(x,py);+ // Six rings spread across the stage, so the pattern shows at once and a stage that is paused still shows it+ function seedRings(){+ const m=Math.max(W,H);+ ringT=t;+ rings=Array.from({length:6},(_,i)=>({r:m*(i+1)/7,c:i%CX}));+ }++ // PRESET 2: Sliding bars+ function drawBars(){+ const count=CX;+ for(let i=0;i<count;i++){+ const x=(barX+i*(W/count)*1.1)%W;+ const barW=W/count*.5;+ const op=.15+.1*Math.sin(t+i*.7);+ ctx.fillStyle=col(i,op);+ // Diagonal slant+ ctx.save();ctx.translate(x,0);+ ctx.beginPath();+ ctx.moveTo(-barW*.2,0);ctx.lineTo(barW*.8,0);ctx.lineTo(barW*.6,H);ctx.lineTo(-barW*.4,H);ctx.closePath();+ ctx.fill();ctx.restore();+ }+ }++ // PRESET 3: Color-flow lines+ function drawLines(){+ const count=CX*2;+ for(let i=0;i<count;i++){+ const y=H*(i+.5)/count;+ const amp=15+i*3;+ const phase=i*.4+t*.8;+ ctx.beginPath();+ for(let x=0;x<=W;x+=4){+ const py=y+Math.sin(x/80+phase)*amp+Math.cos(x/120+phase*.7)*amp*.5;+ x===0?ctx.moveTo(x,py):ctx.lineTo(x,py);+ }+ // Animated dash offset for color flow effect+ const dashLen=40,gapLen=60;+ ctx.setLineDash([dashLen,gapLen]);+ ctx.lineDashOffset=-dashPhase+i*20;+ ctx.strokeStyle=col(i%CX,.6+Math.sin(t+i)*.3);+ ctx.lineWidth=lineW()*(1.5-i*.03);ctx.stroke();+ ctx.setLineDash([]);}- // Animated dash offset for color flow effect- const dashLen=40,gapLen=60;- ctx.setLineDash([dashLen,gapLen]);- ctx.lineDashOffset=-t*30*SPD+i*20;- ctx.strokeStyle=col(i%CX,.6+Math.sin(t+i)*.3);- ctx.lineWidth=lineW()*(1.5-i*.03);ctx.stroke();- ctx.setLineDash([]);}-}--function render(){- ctx.fillStyle=BG;ctx.fillRect(0,0,W,H);- if(PRESET===0)drawPolygons();- else if(PRESET===1){updateRings();drawRings();}- else if(PRESET===2)drawBars();- else drawLines();-}--// Reduced motion: one representative still frame instead of the loop.-function still(){- t=1.2;- if(PRESET===1){const m=Math.max(W,H);ringT=t;rings2=[];for(let i=0;i<6;i++)rings2.push({r:m*(i+1)/7,born:t,c:i%CX});}- render();-}-function repaint(){RM.matches?still():render();}--function loop(ts){- if(paused){raf=null;return;}- if(RM.matches){raf=null;still();return;}- raf=requestAnimationFrame(loop);- const dt=ts-lastT;if(dt<16)return;lastT=ts;- t+=SPD*.01;- render();-}--resize();-raf=requestAnimationFrame(loop);--document.querySelectorAll('.ptab').forEach(b=>{- b.addEventListener('click',()=>{- PRESET=+b.dataset.idx;- document.querySelectorAll('.ptab').forEach(x=>x.classList.remove('active'));- b.classList.add('active');rings2=[];ringT=-1e9;if(!raf)repaint();++ // One step of the loop. k is 1 for a frame at 60 Hz (more or less for a longer or shorter one), and a third of that in+ // slow motion. t, the rings' growth and the bars' and dashes' travel all move by it, so slow motion slows all of them.+ function advance(k){+ const dt=SPD*.01*k;+ t+=dt;barX+=SPD*40*dt;dashPhase+=SPD*30*dt;+ if(PRESET!==1)return;+ const m=Math.max(W,H);+ if(t-ringT>=.5){ringT=t;rings.push({r:0,c:Math.floor(Math.random()*CX)});}+ rings=rings.filter(r=>r.r<m);+ rings.forEach(r=>{r.r+=SPD*2*k;});+ }+ // The whole picture for the current t; the canvas is painted over completely, so no trace of an earlier picture stays+ function draw(){+ ctx.fillStyle=BG;ctx.fillRect(0,0,W,H);+ if(PRESET===0)drawPolygons();+ else if(PRESET===1)drawRings();+ else if(PRESET===2)drawBars();+ else drawLines();+ }++ // loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again. The first frame+ // after a start has no earlier frame to measure from, so it adds no time; a long gap between frames (a background+ // tab) counts for at most 50 ms. At most one picture is drawn per 16 ms.+ function loop(ts){+ raf=requestAnimationFrame(loop);+ if(lastT!==null&&ts-lastT<16)return;+ const dt=lastT===null?0:Math.min(ts-lastT,50);+ lastT=ts;+ advance(dt/FRAME*(slowTog.checked?1/3:1));+ draw();+ }+ function start(){if(raf)return;lastT=null;raf=requestAnimationFrame(loop);}++ // Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses the+ // loop on arrival, which this listener must catch. The picture on screen stays as it is while paused.+ document.addEventListener('hb:pause',e=>{+ paused=e.detail.paused;+ if(paused){cancelAnimationFrame(raf);raf=null;}+ else start();});-});-document.getElementById('spd-sl').addEventListener('input',e=>{SPD=e.target.value/10;document.getElementById('spd-v').textContent=SPD.toFixed(1);if(!raf)repaint();});-document.getElementById('cx-sl').addEventListener('input',e=>{CX=+e.target.value;document.getElementById('cx-v').textContent=CX;if(!raf)repaint();});-document.getElementById('pal-sel').addEventListener('change',e=>{PAL=e.target.value;if(!raf)repaint();});-document.getElementById('bg-sel').addEventListener('change',e=>{BG=e.target.value;if(!raf)repaint();});-document.getElementById('contrast-tog').addEventListener('change',e=>{CONTRAST=e.target.checked;if(!raf)repaint();});-document.getElementById('pause-btn').addEventListener('click',()=>{- paused=!paused;document.getElementById('pause-btn').textContent=paused?'▶ Resume':'⏸ Pause';- if(!paused){lastT=performance.now();raf=requestAnimationFrame(loop);}-});++ // Setting the canvas size wipes it, so a real change of the stage's size draws the picture again at once, playing or+ // paused. A resize that leaves the stage as it was (a phone's address bar sliding in or out) does nothing.+ function resize(){+ const w=stage.clientWidth,h=stage.clientHeight;+ if(w===W&&h===H)return;+ W=w;H=h;+ const dpr=Math.min(window.devicePixelRatio||1,2);+ cvs.width=Math.round(W*dpr);cvs.height=Math.round(H*dpr);+ ctx.setTransform(dpr,0,0,dpr,0,0);+ draw();+ }++ function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+ }+ // A setting that changes the picture draws it again at once, so the change shows even while the loop is paused (or is+ // paused a moment later, before the next frame). Speed changes no picture: the bars and the dashes carry on from where+ // they are, so it needs no drawing. Pressing the choice already made does nothing.+ choices('pat-seg',d=>{+ if(+d.idx===PRESET)return;+ PRESET=+d.idx;+ rings=[];+ if(PRESET===1)seedRings();+ draw();+ });+ choices('speed-seg',d=>{SPD=+d.spd;});+ choices('num-seg',d=>{+ if(+d.n===CX)return;+ CX=+d.n;+ rings.forEach(r=>{r.c=Math.floor(Math.random()*CX);}); // the rings on screen take colors from the new range at once+ draw();+ });+ choices('pal-seg',d=>{PAL=d.pal;draw();});+ document.getElementById('thick-tog').addEventListener('change',e=>{CONTRAST=e.target.checked;draw();});++ resize();+ window.addEventListener('resize',resize);+ start();</script>-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script></body></html>diff --git a/index.html b/index.htmlindex 8d867fb9..1b874e4d 100644--- a/index.html+++ b/index.html@@ -1044,7 +1044,7 @@ const CATS=[['ambient-ripple','Ambient Ripple Effect','Rings spread from a few spots, like drops on a still pond. Best for hero areas.'],['floating-elements','Floating Elements','Small shapes drift slowly, each on its own path. Best for hero backgrounds.'],['grid-dot-pattern-parallax','Grid / Dot Pattern Parallax','A dot grid shifts gently against your pointer for depth. Best for tech sites.'],- ['abstract-geometric-motion','Abstract Geometric Motion','Four hypnotic loops: rotating polygons, expanding rings, sliding bars, flowing color lines.'],+ ['abstract-geometric-motion','Abstract Geometric Motion','Shapes turn, spread and flow in a calm, endless pattern. Best for music players.'],['particle-constellation','Particle Constellation','Drifting nodes link with lines when they come close — the network-mesh hero background.'],['flow-field','Flow Field','Particles follow a noise-driven vector field, leaving flowing trails.'],['synthwave-grid','Synthwave Grid','A perspective grid scrolls toward a glowing sun — the retro synthwave horizon.'],