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: Fireworks (07.20)
matin732f9e0cc6f6
diff --git a/README.md b/README.mdindex 7fa96f2c..a4193983 100644--- a/README.md+++ b/README.md@@ -239,6 +239,7 @@ All 129 techniques, each linked to its live demo.- **[Plasma Field](animations/07-ambient-background/plasma/)** — Smooth waves of color flow endlessly, made from math. Best for creative sites.- **[Wave Layers](animations/07-ambient-background/wave-layers/)** — Layers of waves drift sideways, each at its own speed. Best for hero sections and footers.- **[Snow / Rain](animations/07-ambient-background/snow-rain/)** — Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.+- **[Fireworks](animations/07-ambient-background/fireworks/)** — Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.</details>diff --git a/animations/07-ambient-background/README.md b/animations/07-ambient-background/README.mdindex 63ff1cd0..dc63edc5 100644--- a/animations/07-ambient-background/README.md+++ b/animations/07-ambient-background/README.md@@ -25,6 +25,7 @@ Passive, looping effects that hold visual interest without demanding attention.| [Plasma Field](plasma/) | Smooth waves of color flow endlessly, made from math. Best for creative sites. || [Wave Layers](wave-layers/) | Layers of waves drift sideways, each at its own speed. Best for hero sections and footers. || [Snow / Rain](snow-rain/) | Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages. |+| [Fireworks](fireworks/) | Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations. |## The ambient mindsetdiff --git a/animations/07-ambient-background/fireworks/README.md b/animations/07-ambient-background/fireworks/README.mdnew file mode 100644index 00000000..a42ede00--- /dev/null+++ b/animations/07-ambient-background/fireworks/README.md@@ -0,0 +1,61 @@+# Fireworks++## What it is+A fireworks effect launches rockets from the bottom of a dark scene; each one slows as it climbs and, at the top of its climb, bursts into a ball of sparks that fly out, droop under gravity and fade away. Instead of being cleared, the canvas is covered with a faint see-through layer on every frame, so each spark leaves a glowing trail of the path it has flown.++## When to use it+- Launch, event and countdown pages+- Holiday and New Year greetings+- Success screens after a sign-up, a purchase or a finished course+- Wins and level-ups in games++## How it works+The sky and the skyline are plain HTML behind and in front of a see-through canvas, which holds only the fireworks. A rocket leaves the bottom just fast enough for gravity to stop it at the height where it should burst, and it bursts the moment it stops rising:++```js+const g = .07 * U, top = H * (.2 + Math.random() * .26); // U: the stage's height in 400ths+rockets.push({ x, y: H, vx: (Math.random() - .5) * .5 * U, vy: -Math.sqrt(2 * g * (H - top)), g });+// each step: r.vy += r.g * k; r.x += r.vx * k; r.y += r.vy * k; if (r.vy >= 0) burst(r.x, r.y, …)+```++A burst keeps its sparks in one typed array. For a round burst the speeds follow `sqrt(1 − u²)` for a random `u` between −1 and 1, which is how the sparks of a ball look from the side: thickest at the rim. A ring gives every spark nearly the top speed; a willow starts slower, droops more and lasts longer. Each step slows every spark by its drag and pulls it down:++```js+const d = Math.pow(b.drag, k); // k: 60ths of a second, at most one per step+P[i + 2] *= d; P[i + 3] = P[i + 3] * d + b.g * k; // speed across, speed down+P[i] += P[i + 2] * k; P[i + 1] += P[i + 3] * k;+```++Every frame first covers the canvas with `destination-out` at a fixed opacity, which wears the old picture down toward see-through, so the CSS sky shows through the fading trails. It covers once for every 60th of a second that has passed, at the opacity a 60 Hz screen would use, so trails last as long in seconds on every screen, and a frame with no cover due draws nothing. Then each burst is one stroke from where every spark was when the frame began to where it is now, drawn with `lighter`, so crossing sparks glow brighter:++```js+ctx.globalCompositeOperation = 'destination-out';+ctx.fillStyle = 'rgba(0,0,0,' + WASH[TRAIL] + ')'; // none 1, short .3, long .13+for (let i = 0; i < nf; i++) ctx.fillRect(0, 0, W, H); // nf: covers due this frame+ctx.globalCompositeOperation = 'lighter';+```++A frame longer than a 60th of a second (a 30 Hz phone, a busy moment) is moved in equal steps of at most one 60th, so drag and gravity put every spark where a 60 Hz screen would.++An 8-bit canvas cannot fade a faint pixel all the way to nothing: a pixel at 3/255 covered by 13% becomes 2.61, which rounds back to 3. Left alone, every burst would leave a dim ghost in the sky. So each burst remembers the patch it has lit. When it dies, its rocket's path is wiped with `clearRect`, and half a second later (its last trails need that long to fade) its patch too, on whole device pixels, each as soon as no rocket or other burst still glows there.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| How often | Sometimes | The time between launches, on average: rarely about 2.2 seconds, sometimes 1.2 and often half a second |+| Colors | Many colors | Each burst picks one color: from eight hues, from three golds, or from blues and violets |+| Trails | Long | How much of the picture each 60th of a second's cover takes away: none 100%, short 30% and long 13% |+| Burst shape | Round | A ball of sparks, a ring of sparks that all fly at nearly the same speed, or a willow whose sparks droop like branches |++## Production notes+- **Phones**: the demo gives a burst 50 sparks on phones and short screens (`(max-width: 600px), (max-height: 500px)`) instead of 90, and never keeps more than 300 sparks in the air there (900 elsewhere).+- **One stroke per burst**: all the sparks of a burst share one color and opacity, so they go into one path; a frame with three bursts is three strokes, not hundreds.+- **Flashes**: the glow at each burst is soft and drawn once. Avoid full-screen white flashes, which can trouble people with photosensitive conditions.+- **Libraries**: fireworks-js and the tsParticles fireworks preset do the same with more shell types, and sound; the loop, drag, gravity and trail cover are the same idea.+- **Reduced motion**: show one still burst, as the demo does; never fire bursts on a page someone asked to keep still.++## See also+- [Success Confetti](../../04-micro-interactions/success-confetti/) — one burst of confetti for a single big moment+- [Snow / Rain](../snow-rain/) — particles over the same kind of dark scene, falling instead of bursting+- [Flow Field](../flow-field/) — particles that leave fading trails with the same see-through cover+- [Starfield / Space Particles](../starfield/) — short trails from a cover that is the same on every screendiff --git a/animations/07-ambient-background/fireworks/index.html b/animations/07-ambient-background/fireworks/index.htmlnew file mode 100644index 00000000..ac773d26--- /dev/null+++ b/animations/07-ambient-background/fireworks/index.html@@ -0,0 +1,297 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Fireworks — Animation Handbook</title>+ <meta name="description" content="Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/fireworks/">+ <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">+ <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">+ <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">+ <meta property="og:type" content="article">+ <meta property="og:site_name" content="Animation Handbook">+ <meta property="og:title" content="Fireworks — Animation Handbook">+ <meta property="og:description" content="Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/fireworks/">+ <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="Fireworks — Animation Handbook">+ <meta name="twitter:description" content="Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.">+ <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": "Fireworks", "name": "Fireworks", "description": "Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/fireworks/", "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, Fireworks"}</script>+ <style>+ :root{--ui-accent:#ffce5a}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ /* The sky is the stage's own background: the canvas over it is see-through, and its trails fade to nothing, not to a color */+ .stage{position:relative;overflow:hidden;background:linear-gradient(#02030a,#0b0c22 55%,#221640)}+ canvas{position:absolute;inset:0;display:block;width:100%;height:100%}+ .city{position:absolute;left:0;bottom:0;width:100%;height:24%;display:block}+ </style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=6">+ <script src="../../../assets/js/demo-page.js?v=6" defer></script>+</head>+<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="../snow-rain/" rel="prev" aria-label="Previous: Snow / Rain"><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>Snow / Rain</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">07.20 · Ambient & Background</p>+ <h1>Fireworks</h1>+ <p class="hb-lede">Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.</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>+ <svg class="city" viewBox="0 0 1000 60" preserveAspectRatio="xMidYMax slice" aria-hidden="true">+ <path fill="#05060d" d="M0 60V46H12V28H35V39H65V26H78V30H93V37H122V30H136V45H166V33H193V20H216V37H235V24H265V41H279V41H292V21H306V30H333V18H345V33H365V20H384V39H401V27H415V22H431V39H459V42H479V42H508V46H525V32H538V42H559V39H590V22H602V14H604V22H615V28H643V42H664V44H689V33H709V23H732V22H750V48H758V40H760V48H768V40H798V33H825V24H849V46H879V27H892V18H919V28H934V43H950V18H972V29H988V30H1000V60Z"/>+ <path fill="#f3c26a" fill-opacity=".6" d="M20 44h2v2h-2zM68 42h2v2h-2zM159 49h2v2h-2zM149 55h2v2h-2zM179 43h2v2h-2zM174 49h2v2h-2zM211 24h2v2h-2zM201 36h2v2h-2zM243 46h2v2h-2zM282 51h2v2h-2zM295 25h2v2h-2zM309 34h2v2h-2zM404 31h2v2h-2zM409 37h2v2h-2zM418 26h2v2h-2zM444 43h2v2h-2zM449 55h2v2h-2zM497 52h2v2h-2zM528 48h2v2h-2zM533 48h2v2h-2zM572 43h2v2h-2zM562 55h2v2h-2zM593 26h2v2h-2zM608 26h2v2h-2zM598 38h2v2h-2zM603 44h2v2h-2zM646 46h2v2h-2zM646 52h2v2h-2zM722 39h2v2h-2zM791 50h2v2h-2zM811 37h2v2h-2zM811 49h2v2h-2zM838 28h2v2h-2zM895 28h2v2h-2zM910 34h2v2h-2zM968 22h2v2h-2zM953 34h2v2h-2zM963 46h2v2h-2zM958 52h2v2h-2z"/>+ </svg>+ </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 class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="often-lbl">How often</p>+ <div class="seg" id="often-seg" role="group" aria-labelledby="often-lbl">+ <button type="button" data-often="rarely" aria-pressed="false">Rarely</button>+ <button type="button" data-often="sometimes" class="on" aria-pressed="true">Sometimes</button>+ <button type="button" data-often="often" aria-pressed="false">Often</button>+ </div>+ <p class="hb-hint">Rarely keeps it calm behind text.</p>+ </div>+ <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="many" class="on" aria-pressed="true">Many colors</button>+ <button type="button" data-pal="gold" aria-pressed="false">Gold</button>+ <button type="button" data-pal="blue" aria-pressed="false">Blue</button>+ </div>+ <p class="hb-hint">Each burst picks one color from the set.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="trail-lbl">Trails</p>+ <div class="seg" id="trail-seg" role="group" aria-labelledby="trail-lbl">+ <button type="button" data-trail="none" aria-pressed="false">None</button>+ <button type="button" data-trail="short" aria-pressed="false">Short</button>+ <button type="button" data-trail="long" class="on" aria-pressed="true">Long</button>+ </div>+ <p class="hb-hint">Trails show the path each spark has flown.</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="shape-lbl">Burst shape</p>+ <div class="seg" id="shape-seg" role="group" aria-labelledby="shape-lbl">+ <button type="button" data-shape="round" class="on" aria-pressed="true">Round</button>+ <button type="button" data-shape="ring" aria-pressed="false">Ring</button>+ <button type="button" data-shape="willow" aria-pressed="false">Willow</button>+ </div>+ <p class="hb-hint">Willow sparks droop like the branches of a tree.</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 fireworks to [the dark section you want them over]. On a see-through canvas laid over the section, launch a rocket from the bottom every so often; it slows as it climbs and, at the top of its climb, bursts into many sparks that fly out in all directions. Slow the sparks a little on every frame, pull them gently down and fade them out, so each burst blooms, droops and dies away. For trails, cover the canvas with a faint see-through layer instead of clearing it, the same number of times per second on every screen. Use fewer sparks on phones. If the visitor has reduced motion turned on, show one still burst. 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>Launch and event pages</li><li>Holiday greetings</li><li>Success screens</li><li>Game wins</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Calm brands</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.querySelector('.stage'),slowTog=document.getElementById('slow-tog');+ const phone=matchMedia('(max-width:600px),(max-height:500px)'); // phones and short screens get fewer sparks+ 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+ // [hue, saturation, lightness] a burst can take: Many colors picks any of them, Gold and Blue keep to their own few+ const PALETTES={many:[[0,90,62],[30,95,60],[52,95,62],[130,70,58],[190,85,62],[220,90,70],[280,80,72],[320,85,68]],+ gold:[[36,95,60],[44,100,66],[28,90,58]],blue:[[195,90,66],[215,95,72],[255,85,74],[280,75,74]]};+ const EVERY={rarely:130,sometimes:70,often:32}; // 60ths of a second between launches, on average+ const WASH={none:1,short:.3,long:.13}; // how much of the picture one cover takes away; one cover every 60th of a second+ const STILL=[[.5,.3,24],[.24,.38,40],[.77,.22,12]]; // the still picture's bursts: where (shares of the stage) and how old+ let W=0,H=0,U=1,D=1,raf=null,lastT=null,fa=0,paused=false,wait=0; // U: the stage's height in 400ths; D: device pixels per CSS pixel+ let OFTEN='sometimes',PAL='many',TRAIL='long',SHAPE='round',rockets=[],bursts=[],marks=[]; // marks: faded patches to wipe+ // A rocket leaves the bottom (sx) just fast enough for gravity to stop it at the height where it bursts+ function launch(){+ const x=W*(.15+Math.random()*.7),top=H*(.2+Math.random()*.26),g=.07*U;+ rockets.push({x,y:H,px:x,py:H,sx:x,vx:(Math.random()-.5)*.5*U,vy:-Math.sqrt(2*g*(H-top)),g});+ }+ // A burst keeps its sparks in one typed array: x, y, speed across, speed down, and where the spark was when the frame began.+ // Round spreads the speeds like a ball seen from the side, thickest at the rim; ring gives every spark nearly the top speed;+ // willow sparks start slower, droop more and last longer. box is the patch of sky the burst has lit, its flash included.+ function burst(x,y,sx){+ const c=PALETTES[PAL][Math.floor(Math.random()*PALETTES[PAL].length)],willow=SHAPE==='willow';+ const n=phone.matches?50:90,top=(willow?2.8:4.2)*U,P=new Float32Array(n*6),m=60*U;+ for(let i=0;i<n;i++){+ const a=Math.random()*6.283,u=Math.random()*2-1,v=top*(SHAPE==='ring'?.93+Math.random()*.07:.08+.92*Math.sqrt(1-u*u));+ P.set([x,y,Math.cos(a)*v,Math.sin(a)*v,x,y],i*6);+ }+ bursts.push({P,n,c,x,y,sx,box:[x-m,y-m,x+m,y+m],age:0,life:willow?125:70+Math.random()*20,drag:willow?.972:.955,g:(willow?.05:.032)*U,flash:true});+ }+ const column=(sx,x,y)=>[Math.min(sx,x)-4,y-4,Math.max(sx,x)+4,H]; // the path a rocket has drawn+ // An 8-bit canvas cannot fade a faint pixel to nothing (each cover rounds it back up), so every burst would leave a dim ghost.+ // Once a burst has faded, its patch and its rocket's path are wiped clean on whole device pixels, as soon as no rocket, no+ // burst and no rocket trail of the last half second still glows there.+ function wipe(k){+ const hit=(q,r)=>q[0]<r[2]&&q[2]>r[0]&&q[1]<r[3]&&q[3]>r[1],out=v=>Math.floor(v*D)/D,up=v=>Math.ceil(v*D)/D;+ const busy=r=>rockets.some(q=>hit(column(q.sx,q.x,q.y),r))||bursts.some(b=>hit(b.box,r)||b.age<30&&hit(column(b.sx,b.x,b.y),r));+ marks=marks.filter(m=>{+ if((m.wait-=k)>0||busy(m.r))return true;+ const r=m.r,x=out(r[0]-3),y=out(r[1]-3);ctx.clearRect(x,y,up(r[2]+3)-x,up(r[3]+3)-y);return false;+ });+ }+ // Where everything is when a frame begins: the frame draws every rocket and spark from there to where it ends up+ function keep(){+ for(const r of rockets){r.px=r.x;r.py=r.y;}for(const b of bursts)for(let i=0;i<b.n*6;i+=6){b.P[i+4]=b.P[i];b.P[i+5]=b.P[i+1];}+ }+ // k is how many 60 Hz frames this step stands for, at most one (the loop splits longer ones): speeds fade by drag to the+ // power k and gravity adds k times its pull. A burst that has died leaves its patch to wipe half a second later.+ function step(k,launching){+ if(launching&&(wait-=k)<=0){if(bursts.reduce((s,b)=>s+b.n,0)<(phone.matches?300:900))launch();wait=EVERY[OFTEN]*(.5+Math.random());}+ for(const r of rockets){r.vy+=r.g*k;r.x+=r.vx*k;r.y+=r.vy*k;if(r.vy>=0){burst(r.x,r.y,r.sx);r.done=true;}}+ rockets=rockets.filter(r=>!r.done);+ for(const b of bursts){+ const d=Math.pow(b.drag,k),P=b.P,B=b.box;b.age+=k;+ for(let i=0;i<b.n*6;i+=6){+ P[i+2]*=d;P[i+3]=P[i+3]*d+b.g*k;+ const x=P[i]+=P[i+2]*k,y=P[i+1]+=P[i+3]*k;+ if(x<B[0])B[0]=x;else if(x>B[2])B[2]=x;+ if(y<B[1])B[1]=y;else if(y>B[3])B[3]=y;+ }+ }+ for(const b of bursts)if(b.age>=b.life)marks.push({r:b.box,wait:30},{r:column(b.sx,b.x,b.y),wait:0});+ bursts=bursts.filter(b=>b.age<b.life);+ wipe(k);+ }+ // nf covers wear the old picture down toward see-through (with no trails one cover takes it all), then everything is drawn+ // added on top, so sparks that cross glow brighter. A burst is one stroke: its sparks share a color, start white-hot, then+ // fade and crackle as it ages; on its first frame it also lights a soft glow, which the covers fade with the trails.+ function paint(nf){+ ctx.globalCompositeOperation='destination-out';ctx.fillStyle='rgba(0,0,0,'+WASH[TRAIL]+')';+ for(let i=0;i<nf;i++)ctx.fillRect(0,0,W,H);+ ctx.globalCompositeOperation='lighter';ctx.lineCap='round';+ ctx.lineWidth=2;ctx.strokeStyle='rgba(255,226,180,.9)';ctx.beginPath();+ for(const r of rockets){ctx.moveTo(r.px,r.py);ctx.lineTo(r.x,r.y);}+ ctx.stroke();ctx.lineWidth=1.7;+ for(const b of bursts){+ const t=b.age/b.life,[h,s,l]=b.c,P=b.P,hsl='hsla('+h+','+s+'%,';+ if(b.flash){+ const r=60*U,g=ctx.createRadialGradient(b.x,b.y,0,b.x,b.y,r);b.flash=false;+ g.addColorStop(0,hsl+l+'%,.3)');g.addColorStop(1,hsl+l+'%,0)');ctx.fillStyle=g;ctx.fillRect(b.x-r,b.y-r,2*r,2*r);+ }+ ctx.strokeStyle=hsl+(t<.1?90:l)+'%,'+Math.min(1,(1-t)*1.3)+')';ctx.beginPath();+ for(let i=0;i<b.n*6;i+=6){if(t>.55&&Math.random()<.35)continue;ctx.moveTo(P[i+4],P[i+5]);ctx.lineTo(P[i],P[i+1]);}+ ctx.stroke();+ }+ ctx.globalCompositeOperation='source-over';+ }+ // The still picture: at the start, after a resize and when a setting changes while paused. One, two or three bursts (as+ // How often asks) at set places and ages are played forward a 60th of a second at a time, so their trails build up as live.+ function paintStill(){+ rockets=[];bursts=[];marks=[];ctx.clearRect(0,0,W,H);+ const shots=STILL.slice(0,{rarely:1,sometimes:2,often:3}[OFTEN]),T=Math.max(...shots.map(s=>s[2]));+ for(let t=0;t<=T;t++){for(const [x,y,age] of shots)if(T-t===age)burst(W*x,H*y,W*x);keep();step(1,false);paint(1);}+ wait=EVERY[OFTEN]*.5;+ }+ // loop() keeps one frame requested in raf. A drawn frame stands for the time since the last drawn one (n, at most 50 ms) and+ // covers once per whole 60th, fa carrying the rest; with no cover due nothing is drawn and the time carries on, which also+ // caps drawing near 60 a second. The sparks move by n, a third of it in slow motion (the covers do not slow), in equal+ // steps of at most one 60th, so drag and gravity end where a 60 Hz screen would have them.+ function loop(ts){+ raf=requestAnimationFrame(loop);+ if(lastT===null){lastT=ts;return;}+ const n=Math.min(ts-lastT,50)/FRAME,w=Math.max(1,Math.round(n));+ const f=fa+(Math.abs(n-w)<.05?w:n),nf=Math.round(f+.05); // within 5% of a whole number counts as it; .05 keeps a tie off the edge+ if(!nf)return;+ fa=f-nf;lastT=ts;+ const k=n*(slowTog.checked?1/3:1),parts=Math.ceil(k-.05);+ keep();for(let i=0;i<parts;i++)step(k/parts,true);+ paint(nf);+ }+ function start(){if(raf)return;lastT=null;fa=0;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, and the still picture of bursts stays on screen.+ document.addEventListener('hb:pause',e=>{paused=e.detail.paused;if(paused){cancelAnimationFrame(raf);raf=null;}else start();});+ // A tab that comes back after being hidden has no earlier frame to measure from, so its first frame adds no step+ document.addEventListener('visibilitychange',()=>{lastT=null;fa=0;});++ // Setting the canvas size wipes it, so a real change of the stage's size draws the still picture 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;U=H/400;D=Math.min(window.devicePixelRatio||1,2);+ cvs.width=Math.round(W*D);cvs.height=Math.round(H*D);ctx.setTransform(D,0,0,D,0,0);+ paintStill();+ }+ function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ if(b.classList.contains('on'))return; // pressing the choice already made does nothing+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+ }+ // Paused, a change draws a new still picture, so it shows at once. Playing, trails change at once, How often from the next+ // launch, and a new color or shape sends the next rocket up within a fifth of a second.+ function changed(soon){if(paused)paintStill();else if(soon)wait=Math.min(wait,12);}+ choices('often-seg',d=>{OFTEN=d.often;wait=Math.min(wait,EVERY[OFTEN]);changed(false);});+ choices('pal-seg',d=>{PAL=d.pal;changed(true);});+ choices('trail-seg',d=>{TRAIL=d.trail;changed(false);});+ choices('shape-seg',d=>{SHAPE=d.shape;changed(true);});++ resize();+ window.addEventListener('resize',resize);+ start();+</script>+</body>+</html>diff --git a/animations/07-ambient-background/snow-rain/index.html b/animations/07-ambient-background/snow-rain/index.htmlindex ca4475eb..6e2c957e 100644--- a/animations/07-ambient-background/snow-rain/index.html+++ b/animations/07-ambient-background/snow-rain/index.html@@ -34,7 +34,7 @@<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="../wave-layers/" rel="prev" aria-label="Previous: Wave Layers"><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>Wave Layers</span></a></span>+ <span class="hb-pager"><a href="../wave-layers/" rel="prev" aria-label="Previous: Wave Layers"><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>Wave Layers</span></a><a href="../fireworks/" rel="next" aria-label="Next: Fireworks"><span><span class="hb-dir">Next: </span>Fireworks</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">diff --git a/index.html b/index.htmlindex 0c81ead1..61410a06 100644--- a/index.html+++ b/index.html@@ -835,6 +835,20 @@ button,input{font:inherit;color:inherit}clip-path:polygon(0 100%,0 52%,9% 30%,18% 52%,22% 52%,27% 18%,32% 52%,36% 52%,46% 26%,56% 52%,59% 52%,64% 22%,69% 52%,72% 52%,82% 30%,92% 52%,95% 52%,98% 34%,100% 44%,100% 100%)}@keyframes d-sn{to{transform:translateY(60px)}}@keyframes d-sn2{50%{transform:translate(5px,45px)}100%{transform:translate(0,90px)}}+/* Fireworks: three times per cycle a rocket climbs to a point and a burst opens there, one after another: sixteen rays (a+ conic gradient, cut by a radial mask into rays brightest at their tips) grow, droop and fade; a dark skyline stands in front */+.pv-fireworks{background:linear-gradient(#02030a,#0b0c22 55%,#221640);overflow:hidden}+.pv-fireworks .fw{position:absolute;width:38%;aspect-ratio:1;margin:-19% 0 0 -19%;opacity:0;background:repeating-conic-gradient(var(--fc) 0 3deg,transparent 4.5deg 22.5deg);+ -webkit-mask:radial-gradient(closest-side,transparent 22%,rgba(0,0,0,.35) 50%,#000 86%,transparent 92%);mask:radial-gradient(closest-side,transparent 22%,rgba(0,0,0,.35) 50%,#000 86%,transparent 92%);+ animation:d-fw 3.2s ease-out infinite}+.pv-fireworks .rk{position:absolute;width:2px;height:12%;margin-left:-1px;border-radius:2px;background:linear-gradient(#fff3d6,transparent);opacity:0;animation:d-rk 3.2s ease-out infinite}+.pv-fireworks .f1,.pv-fireworks .r1{left:31%;top:48%;--fc:var(--accent);--t:433%}+.pv-fireworks .f2,.pv-fireworks .r2{left:70%;top:30%;--fc:var(--c5);--t:583%;animation-delay:-1.07s}+.pv-fireworks .f3,.pv-fireworks .r3{left:50%;top:40%;--fc:var(--c1);--t:500%;animation-delay:-2.13s}+.pv-fireworks .city{position:absolute;left:0;right:0;bottom:0;height:20%;background:linear-gradient(#f3c26a 0 0) 10% 62%/3px 3px no-repeat,linear-gradient(#f3c26a 0 0) 28% 40%/3px 3px no-repeat,linear-gradient(#f3c26a 0 0) 48% 58%/3px 3px no-repeat,linear-gradient(#f3c26a 0 0) 63% 36%/3px 3px no-repeat,linear-gradient(#f3c26a 0 0) 91% 52%/3px 3px no-repeat,#05060d;+ clip-path:polygon(0 100%,0 40%,8% 40%,8% 15%,14% 15%,14% 55%,22% 55%,22% 30%,27% 30%,27% 0,30% 0,30% 30%,36% 30%,36% 60%,45% 60%,45% 25%,52% 25%,52% 45%,60% 45%,60% 10%,66% 10%,66% 50%,74% 50%,74% 30%,80% 30%,80% 55%,88% 55%,88% 20%,94% 20%,94% 45%,100% 45%,100% 100%)}+@keyframes d-fw{0%,30%{transform:scale(.2);opacity:0}34%{opacity:1}100%{transform:translateY(8%) scale(1);opacity:0}}+@keyframes d-rk{0%{transform:translateY(var(--t));opacity:0}5%{opacity:1}28%{transform:translateY(0);opacity:1}32%,100%{transform:translateY(0);opacity:0}}/* ── bespoke: added demos ── */.pv-magnet{background:#08090c;display:grid;place-items:center;position:relative}@@ -1026,7 +1040,7 @@ button,input{font:inherit;color:inherit}<section class="wrap home-hero" aria-labelledby="hero-title"><span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span><span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>132 free animations · no coding needed</p><h1 class="h1" id="hero-title">What do you want to animate?</h1><p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p><form class="search" id="search-form" role="search" action="./" method="get">@@ -1083,8 +1097,8 @@ button,input{font:inherit;color:inherit}<p class="empty-s">Try a simpler word, or pick one of these:</p><p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p></div>- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>- <noscript><p class="noscript">This page shows its animations with JavaScript. All 131 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript>+ <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 132 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 132 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/<category>/<name>/</code>.</p></noscript></section><section class="how" id="how" aria-labelledby="how-title">@@ -1102,7 +1116,7 @@ button,input{font:inherit;color:inherit}<footer class="wrap foot"><a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>- <p class="foot-t">131 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">132 web animations with live demos and copyable prompts.</p><nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav></footer><div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>@@ -1296,6 +1310,7 @@ const CATS=[['plasma','Plasma Field','Smooth waves of color flow endlessly, made from math. Best for creative sites.'],['wave-layers','Wave Layers','Layers of waves drift sideways, each at its own speed. Best for hero sections and footers.'],['snow-rain','Snow / Rain','Snow drifts down, or rain falls in streaks, over a dark town. Best for seasonal pages.'],+ ['fireworks','Fireworks','Rockets rise and burst into glowing sparks that fall and fade. Best for celebrations.'],]}];@@ -1306,7 +1321,7 @@ const PV={'hamburger-menu-toggle':'hamb','theme-toggle-morph':'thememorph','copy-to-clipboard':'copyfx','star-rating':'stars','toast-notification':'toast','segmented-control':'segct','pull-to-refresh':'pullref','flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv',- 'wave-layers':'wavelayers','snow-rain':'snowrain',+ 'wave-layers':'wavelayers','snow-rain':'snowrain','fireworks':'fireworks','parallax-depth-of-field':'dof','parallax-scrolling':'plx','reverse-scrolling-columns':'revcol','cover-card-to-fixed-header':'cover','fly-in-fly-out-contact-list':'flylist','stacking-cards':'stack','scroll-trigger':'trigger','scrub-animation':'scrub','pin-animation':'pin','snap-scrolling':'snap',@@ -1480,7 +1495,8 @@ const PLACES={'matrix-rain':['bg'],'plasma':['bg'],'wave-layers':['bg','intro'],- 'snow-rain':['bg']+ 'snow-rain':['bg'],+ 'fireworks':['bg','intro']};// The eight cards of "Good places to start", in this order.const PICKS=['click-ripple','typewriter-effect','flip-card-3d','aurora','hamburger-menu-toggle','loading-spinner','parallax-scrolling','slide-up-reveal'];@@ -1497,6 +1513,7 @@ function pvMarkup(k){case 'wavelayers': {let d='M0 0C18 0 32 40 50 40';for(let s=1;s<16;s++)d+='S'+(s*50+32)+(s%2?' 0 ':' 40 ')+(s*50+50)+(s%2?' 0':' 40');return [800,600,400].map((w,k)=>'<span class="wl l'+(k+1)+' anim"><svg viewBox="0 0 '+w+' 40" preserveAspectRatio="none"><path d="'+d+'V40H0Z"/></svg><i></i></span>').join('');}case 'snowrain': return '<span class="sn anim"></span><span class="sn s2 anim"></span><span class="town"></span>';+ case 'fireworks': return [1,2,3].map(k=>'<span class="rk r'+k+' anim"></span>').join('')+[1,2,3].map(k=>'<span class="fw f'+k+' anim"></span>').join('')+'<span class="city"></span>';case 'aurora': return '<span class="band b1 anim"></span><span class="band b2 anim"></span><span class="band b3 anim"></span>';case 'mesh': return '<span class="m m1 anim"></span><span class="m m2 anim"></span><span class="m m3 anim"></span>';case 'glow': return '<span class="core anim"></span><span class="ring anim"></span>';diff --git a/sitemap.xml b/sitemap.xmlindex 8f85acce..b09eabdf 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -132,4 +132,5 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/plasma/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/wave-layers/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/snow-rain/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/fireworks/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url></urlset>