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: Light Rays (07.22)
matinf991d797eaf9
diff --git a/README.md b/README.mdindex 0ca817ea..99f49f09 100644--- a/README.md+++ b/README.md@@ -238,6 +238,7 @@ All 129 techniques, each linked to its live demo.- **[Matrix Rain](animations/07-ambient-background/matrix-rain/)** — Columns of glowing characters rain down a dark screen. Best for tech themes.- **[Plasma Field](animations/07-ambient-background/plasma/)** — Smooth waves of color flow endlessly, made from math. Best for creative sites.- **[Topographic Lines](animations/07-ambient-background/topographic-lines/)** — Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.+- **[Light Rays](animations/07-ambient-background/light-rays/)** — Soft beams of light fall from above and slowly sweep across. Best for hero intros.</details>diff --git a/animations/07-ambient-background/README.md b/animations/07-ambient-background/README.mdindex 4259fbb1..93873882 100644--- a/animations/07-ambient-background/README.md+++ b/animations/07-ambient-background/README.md@@ -24,6 +24,7 @@ Passive, looping effects that hold visual interest without demanding attention.| [Matrix Rain](matrix-rain/) | Columns of glowing characters rain down a dark screen. Best for tech themes. || [Plasma Field](plasma/) | Smooth waves of color flow endlessly, made from math. Best for creative sites. || [Topographic Lines](topographic-lines/) | Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands. |+| [Light Rays](light-rays/) | Soft beams of light fall from above and slowly sweep across. Best for hero intros. |## The ambient mindsetdiff --git a/animations/07-ambient-background/light-rays/README.md b/animations/07-ambient-background/light-rays/README.mdnew file mode 100644index 00000000..98cb032a--- /dev/null+++ b/animations/07-ambient-background/light-rays/README.md@@ -0,0 +1,59 @@+# Light Rays++## What it is+Light rays (also called god rays or sunbeams) are soft shafts of light that fan out from a bright point just out of view, as when sun falls through a window or between trees. Each beam is soft at its edges, brightest near where the light comes in and fading farther away. The beams sway a little and brighten and dim on their own slow cycles, so the light seems to sweep across the scene, and specks of dust glint only where a beam catches them.++## When to use it+- Hero sections and page intros that should feel calm, warm or a little cinematic+- Wellness, nature, travel, church and event sites, where light carries the mood+- Product launches and reveals, with the product or headline sitting in the light+- Dark sections that need depth without a busy pattern++## How it works+Each beam is a soft wedge drawn on a canvas with a conic gradient centered on the light's source: clear at both edges and brightest in the middle. The wedges are drawn with the `lighter` blend, so where two beams overlap their light adds up, over a faint haze that covers the whole fan. Then one radial gradient, drawn with `destination-in`, fades everything with distance from the source.++```js+ctx.globalCompositeOperation = 'lighter';+for (const r of rays) {+ r.now = base + r.c + r.s * Math.sin(r.f * t + r.p) + sweep; // the beam sways on its own cycle+ r.al = r.a * (0.6 + 0.4 * Math.sin(r.g * t + r.q)); // and brightens and dims on another+ const g = ctx.createConicGradient(r.now - r.w / 2, sx, sy), k = r.w / (2 * Math.PI);+ g.addColorStop(0, `rgba(${rgb},0)`);+ g.addColorStop(k * 0.2, `rgba(${rgb},${r.al * 0.3})`);+ g.addColorStop(k * 0.5, `rgba(${rgb},${r.al})`); // brightest along its middle line+ g.addColorStop(k * 0.8, `rgba(${rgb},${r.al * 0.3})`);+ g.addColorStop(k, `rgba(${rgb},0)`);+ ctx.fillStyle = g;+ ctx.beginPath(); ctx.moveTo(sx, sy); // a triangle a little wider than the wedge+ ctx.lineTo(sx + Math.cos(r.now - r.w) * R, sy + Math.sin(r.now - r.w) * R);+ ctx.lineTo(sx + Math.cos(r.now + r.w) * R, sy + Math.sin(r.now + r.w) * R);+ ctx.fill();+}+ctx.globalCompositeOperation = 'destination-in'; // fade with distance from the source+ctx.fillStyle = fade; ctx.fillRect(0, 0, W, H);+```++Each speck of dust drifts up and sideways with a gentle wobble. Its brightness is the light at its spot: every beam that covers it adds its strength, most along the beam's middle line, times the same fade with distance, so a speck glints as a beam passes over it and is barely there in the dark. The light has its own clock, which grows by the time since the last frame times the speed (a third of it in slow motion), never more than 50 ms at once, so the beams sway at the same pace on every screen; every frame clears the canvas and draws the whole picture again.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Light color | Warm | Warm late sunshine over a brown-black room, or cool moonlight over a blue-black one |+| Speed | Normal | How fast the beams sway and the dust drifts: slow is half the normal pace and fast twice it; at normal a beam sways back and forth every 12 to 22 seconds |+| Floating dust | on | Specks of dust drift slowly upward and glint where a beam crosses them; phones show 40, other screens 80 |+| Number of rays | Some | Few is 5 beams, some 8 and many 12; more beams overlap into a fuller, brighter light |+| Light comes from | Top left | Where the beams start: just above the top left corner, the middle of the top edge or the top right corner |++## Production notes+- **Cheap to draw**: a frame is one haze fill, one gradient wedge per beam, one fade, one glow and a few dozen dots, a fraction of a millisecond on a laptop. Nothing is blurred: the soft edges come from the gradient itself, which is far cheaper than a blur filter.+- **Phones**: phone-sized screens (up to 600px wide, or up to 500px tall for a phone held sideways) float half as much dust.+- **Browser support**: `createConicGradient` on a canvas is in every current browser (Chrome 99, Safari 16.1, Firefox 112). For older ones, fill each wedge with a flat, faint color instead.+- **CSS alternative**: beams can also be long, narrow elements with a soft gradient across them, turned around the source with `transform: rotate()` and faded with a mask. Keep them few and narrow, since every one is a large layer in memory, especially on high-density phone screens.+- **WebGL**: games and 3D scenes make god rays with a radial blur of the bright parts of the image (volumetric light scattering); three.js has a `GodRaysEffect` in the postprocessing library.+- **Reduced motion**: the demo starts paused with the rays drawn still, until the visitor presses Play.+- **Keep text readable**: the beams fade out toward the bottom, where the headline sits; keep the brightest part of the light away from small text.++## See also+- [Light Leak](../light-leak/) — warm light washes in from a corner at random times+- [Aurora / Northern Lights](../aurora/) — bands of colored light sway across a night sky+- [Breathing / Pulsing Glow](../breathing-glow/) — one soft glow slowly grows and shrinksdiff --git a/animations/07-ambient-background/light-rays/index.html b/animations/07-ambient-background/light-rays/index.htmlnew file mode 100644index 00000000..20d83f00--- /dev/null+++ b/animations/07-ambient-background/light-rays/index.html@@ -0,0 +1,299 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Light Rays — Animation Handbook</title>+ <meta name="description" content="Soft beams of light fall from above and slowly sweep across. Best for hero intros.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-rays/">+ <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="Light Rays — Animation Handbook">+ <meta property="og:description" content="Soft beams of light fall from above and slowly sweep across. Best for hero intros.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-rays/">+ <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="Light Rays — Animation Handbook">+ <meta name="twitter:description" content="Soft beams of light fall from above and slowly sweep across. Best for hero intros.">+ <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": "Light Rays", "name": "Light Rays", "description": "Soft beams of light fall from above and slowly sweep across. Best for hero intros.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/light-rays/", "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, Light Rays"}</script>+ <style>+ :root{--ui-accent:#ffce5a}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ /* A dark room, a little lighter where the light comes in (--sx, set by the script) */+ .stage{position:relative;overflow:hidden;--sx:6%;background:radial-gradient(ellipse 90% 75% at var(--sx) 0%,#2a1c0f,#120c08 55%,#070505)}+ .stage[data-tone="cool"]{background:radial-gradient(ellipse 90% 75% at var(--sx) 0%,#14223a,#09101c 55%,#04060a)}+ canvas{position:absolute;inset:0;display:block;width:100%;height:100%}+ .fg{position:absolute;left:50%;bottom:clamp(18px,9%,40px);transform:translateX(-50%);width:min(86%,440px);text-align:center;z-index:1;pointer-events:none}+ .fg-eyebrow{font-size:11px;font-weight:600;letter-spacing:2px;text-transform:uppercase;color:rgba(255,255,255,.72);margin-bottom:6px}+ .fg-title{font-size:clamp(18px,3.2vw,28px);font-weight:800;line-height:1.2;color:#fff;text-wrap:balance}+ </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="../topographic-lines/" rel="prev" aria-label="Previous: Topographic Lines"><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>Topographic Lines</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">07.22 · Ambient & Background</p>+ <h1>Light Rays</h1>+ <p class="hb-lede">Soft beams of light fall from above and slowly sweep across. Best for hero intros.</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" data-tone="warm">+ <canvas id="cvs" aria-hidden="true"></canvas>+ <div class="fg">+ <p class="fg-eyebrow">Light rays</p>+ <p class="fg-title">A soft, slow start for your page</p>+ </div>+ </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="tone-lbl">Light color</p>+ <div class="seg" id="tone-seg" role="group" aria-labelledby="tone-lbl">+ <button type="button" data-tone="warm" class="on" aria-pressed="true">Warm</button>+ <button type="button" data-tone="cool" aria-pressed="false">Cool</button>+ </div>+ <p class="hb-hint">Warm is late sunshine; cool is moonlight.</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.5" aria-pressed="false">Slow</button>+ <button type="button" data-spd="1" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-spd="2" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">How fast the beams sway and the dust drifts.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Floating dust</span><input class="hb-switch" type="checkbox" role="switch" id="dust-tog" checked autocomplete="off"></label>+ <p class="hb-hint">Specks of dust drift and glint where the light falls.</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="count-lbl">Number of rays</p>+ <div class="seg" id="count-seg" role="group" aria-labelledby="count-lbl">+ <button type="button" data-n="5" aria-pressed="false">Few</button>+ <button type="button" data-n="8" class="on" aria-pressed="true">Some</button>+ <button type="button" data-n="12" aria-pressed="false">Many</button>+ </div>+ <p class="hb-hint">More rays overlap into a fuller, brighter light.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="from-lbl">Light comes from</p>+ <div class="seg" id="from-seg" role="group" aria-labelledby="from-lbl">+ <button type="button" data-from="left" class="on" aria-pressed="true">Top left</button>+ <button type="button" data-from="top" aria-pressed="false">Top</button>+ <button type="button" data-from="right" aria-pressed="false">Top right</button>+ </div>+ <p class="hb-hint">Where the beams start.</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 soft light rays to [the dark section you want them in]. From one point just above the top edge, draw a fan of long, narrow beams on a canvas, each soft at its edges, brightest near the source and fading to nothing farther away. Let each beam sway a little and brighten and dim on its own slow cycle, so the light seems to sweep across the scene, and add the beams together where they overlap. When the settings include dust, float tiny specks that glint only where a beam crosses them, with fewer specks on phones. Keep the content above the light. If the visitor has reduced motion turned on, show the rays still. 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>Hero sections</li><li>Page intros</li><li>Nature and wellness sites</li><li>Product launches</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Light pages</li><li>Busy layouts</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');+ const slowTog=document.getElementById('slow-tog');+ const TAU=Math.PI*2;+ const LIGHT={warm:'255,212,150',cool:'168,204,255'},SPECK={warm:'255,236,205',cool:'220,234,255'};+ const PHONE_MOTES=40,MOTES=80; // phones and short screens float half as many specks of dust+ const phone=matchMedia('(max-width:600px),(max-height:500px)');+ let W=0,H=0,raf=null,lastT=null;+ let TONE='warm',SPD=1,DUST=true,COUNT=8,FROM='left';+ let clock=0; // the light's own time in seconds: it moves only while the loop runs, so Play carries on with no jump+ let rays=[],motes=[],sx=0,sy=0,base=0,reach=1,fade=null,glow=null;++ // The beams: each has its place in the fan (c), a width and a strength, and its own slow sway and slow brightening+ function build(){+ const spread=.55;+ rays=Array.from({length:COUNT},(_,i)=>({+ c:-spread+(i+.5+(Math.random()-.5)*.6)*2*spread/COUNT,w:.1+Math.random()*.16,a:.14+Math.random()*.16,+ s:.025+Math.random()*.04,f:TAU/(12+Math.random()*10),p:Math.random()*TAU,+ g:TAU/(6+Math.random()*6),q:Math.random()*TAU,now:0,al:0+ }));+ }+ // Specks of dust: each drifts up and sideways with a gentle wobble and twinkles on its own rhythm+ function scatter(){+ motes=Array.from({length:phone.matches?PHONE_MOTES:MOTES},()=>({x:Math.random()*W,y:Math.random()*H,r:.7+Math.random()*1.3,+ vx:(Math.random()-.5)*6,vy:-(2+Math.random()*5),w:TAU/(5+Math.random()*6),tw:TAU/(1.5+Math.random()*3),p:Math.random()*TAU}));+ }+ // Where the light starts (a little above the top edge) and the direction its fan points; the room is lighter there too+ function aim(){+ const fx=FROM==='left'?.06:FROM==='right'?.94:.5,tx=FROM==='left'?.64:FROM==='right'?.36:.5;+ sx=W*fx;sy=-H*.14;base=Math.atan2(H-sy,W*tx-sx);reach=Math.hypot(W,H)*1.05;+ stage.style.setProperty('--sx',fx*100+'%');+ fade=ctx.createRadialGradient(sx,sy,0,sx,sy,reach);+ fade.addColorStop(0,'#000');fade.addColorStop(.5,'rgba(0,0,0,.75)');fade.addColorStop(1,'rgba(0,0,0,0)');+ glow=ctx.createRadialGradient(sx,sy,0,sx,sy,Math.min(W,H)*.8);+ glow.addColorStop(0,`rgba(${LIGHT[TONE]},.3)`);glow.addColorStop(1,`rgba(${LIGHT[TONE]},0)`);+ }+ // How brightly the beams light one spot: every beam that covers it adds its strength, most at its middle line+ function lightAt(x,y){+ const d=Math.hypot(x-sx,y-sy)/reach,ang=Math.atan2(y-sy,x-sx);+ if(d>=1)return 0;+ let sum=0;+ for(const r of rays){const u=(ang-r.now)*2/r.w;if(u>-1&&u<1){const b=1-u*u;sum+=r.al*b*b;}}+ return sum*(1-d);+ }+ // The whole picture at the light's current time. Each beam is a soft wedge: a conic gradient around the source, clear at+ // both edges and brightest in the middle, drawn with 'lighter' so overlapping beams add up. 'destination-in' with a radial+ // gradient then fades all of them with distance, and the dust is drawn on top, as bright as the light where each speck is.+ function draw(){+ const rgb=LIGHT[TONE],t=clock,sweep=.06*Math.sin(t*.11),R=reach*1.3;+ ctx.clearRect(0,0,W,H);+ ctx.globalCompositeOperation='lighter';+ // a faint haze over the whole fan, so the beams shine through lit air instead of a black room+ const hz=ctx.createConicGradient(base-.75+sweep,sx,sy),h=1.5/TAU;+ hz.addColorStop(0,`rgba(${rgb},0)`);hz.addColorStop(h*.3,`rgba(${rgb},.07)`);hz.addColorStop(h*.7,`rgba(${rgb},.07)`);hz.addColorStop(h,`rgba(${rgb},0)`);+ ctx.fillStyle=hz;ctx.fillRect(0,0,W,H);+ for(const r of rays){+ r.now=base+r.c+r.s*Math.sin(r.f*t+r.p)+sweep;+ r.al=r.a*(.6+.4*Math.sin(r.g*t+r.q));+ const g=ctx.createConicGradient(r.now-r.w/2,sx,sy),k=r.w/TAU;+ g.addColorStop(0,`rgba(${rgb},0)`);g.addColorStop(k*.2,`rgba(${rgb},${r.al*.3})`);g.addColorStop(k*.5,`rgba(${rgb},${r.al})`);+ g.addColorStop(k*.8,`rgba(${rgb},${r.al*.3})`);g.addColorStop(k,`rgba(${rgb},0)`);+ ctx.fillStyle=g;+ ctx.beginPath();ctx.moveTo(sx,sy);ctx.lineTo(sx+Math.cos(r.now-r.w)*R,sy+Math.sin(r.now-r.w)*R);+ ctx.lineTo(sx+Math.cos(r.now+r.w)*R,sy+Math.sin(r.now+r.w)*R);ctx.fill();+ }+ ctx.globalCompositeOperation='destination-in';ctx.fillStyle=fade;ctx.fillRect(0,0,W,H);+ ctx.globalCompositeOperation='lighter';ctx.fillStyle=glow;ctx.fillRect(0,0,W,H);+ ctx.globalCompositeOperation='source-over';+ if(!DUST)return;+ ctx.fillStyle=`rgb(${SPECK[TONE]})`;+ for(const m of motes){+ ctx.globalAlpha=Math.min(1,.06+4*lightAt(m.x,m.y)*(.65+.35*Math.sin(m.tw*t+m.p)));+ ctx.beginPath();ctx.arc(m.x,m.y,m.r,0,TAU);ctx.fill();+ }+ ctx.globalAlpha=1;+ }+ // The dust moves on by s seconds of the light's own time, coming back in at the bottom when it leaves at the top+ function drift(s){+ for(const m of motes){+ m.x+=(m.vx+5*Math.sin(m.w*clock+m.p))*s;m.y+=m.vy*s;+ if(m.y<-4){m.y=H+4;m.x=Math.random()*W;}+ if(m.x<-4)m.x=W+4;else if(m.x>W+4)m.x=-4;+ }+ }++ // loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again. At most one picture per+ // 16 ms. The light's time grows by the time since the last picture (never more than 50 ms, so a background tab does not+ // leap) times Speed, or a third of that in slow motion; the first frame after a start has nothing to measure from and adds none.+ 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;+ const s=dt/1000*SPD*(slowTog.checked?1/3:1);+ clock+=s;drift(s);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 rays on screen stay as they are while paused.+ document.addEventListener('hb:pause',e=>{+ if(e.detail.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 time+ document.addEventListener('visibilitychange',()=>{lastT=null;});++ // Setting the canvas size wipes it, so a real change of the stage's size aims the light and draws it 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);+ aim();scatter();draw();+ }++ 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);+ }));+ }+ // A setting that changes the picture draws it at once, so the change shows while the loop is paused. Speed changes no+ // picture: the beams carry on from where they are, at the new pace.+ choices('tone-seg',d=>{TONE=d.tone;stage.dataset.tone=TONE;aim();draw();});+ choices('speed-seg',d=>{SPD=+d.spd;});+ document.getElementById('dust-tog').addEventListener('change',e=>{DUST=e.target.checked;draw();});+ choices('count-seg',d=>{COUNT=+d.n;build();draw();});+ choices('from-seg',d=>{FROM=d.from;aim();draw();});++ build();resize();+ window.addEventListener('resize',resize);+ // A window that crosses the phone size changes how many specks of dust it shows, even when the stage keeps its size+ phone.addEventListener('change',()=>{if((phone.matches?PHONE_MOTES:MOTES)!==motes.length){scatter();draw();}});+ start();+</script>+</body>+</html>diff --git a/animations/07-ambient-background/topographic-lines/index.html b/animations/07-ambient-background/topographic-lines/index.htmlindex 168f3658..5437577e 100644--- a/animations/07-ambient-background/topographic-lines/index.html+++ b/animations/07-ambient-background/topographic-lines/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="../plasma/" rel="prev" aria-label="Previous: Plasma Field"><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>Plasma Field</span></a></span>+ <span class="hb-pager"><a href="../plasma/" rel="prev" aria-label="Previous: Plasma Field"><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>Plasma Field</span></a><a href="../light-rays/" rel="next" aria-label="Next: Light Rays"><span><span class="hb-dir">Next: </span>Light Rays</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 6028fac2..4a327968 100644--- a/index.html+++ b/index.html@@ -825,6 +825,12 @@ button,input{font:inherit;color:inherit}.pv-topo .h2{transform-origin:150px 10px;animation:d-topo 7s ease-in-out infinite alternate-reverse}.pv-topo .h3{transform-origin:152px 98px;animation:d-topo 8s ease-in-out infinite alternate-reverse}@keyframes d-topo{from{transform:rotate(-6deg) scale(.95)}to{transform:rotate(6deg) scale(1.05)}}+/* soft beams fan out from just above the top right corner, each swaying and brightening on its own cycle, over drifting dust */+.pv-rays{background:radial-gradient(ellipse 90% 80% at 92% 0%,#2a1c0f,#120c08 55%,#070505);overflow:hidden}+.pv-rays i{position:absolute;left:83%;top:-14%;width:18%;height:200%;transform-origin:50% 0;background:linear-gradient(90deg,transparent,color-mix(in srgb,var(--accent) 30%,transparent),transparent);clip-path:polygon(42% 0,58% 0,100% 100%,0 100%);-webkit-mask:linear-gradient(#000 5%,transparent 70%);mask:linear-gradient(#000 5%,transparent 70%);animation:d-rays 7s ease-in-out infinite alternate}+.pv-rays b{position:absolute;width:3px;height:3px;border-radius:50%;background:#fff3dc;animation:d-dust 6s ease-in-out infinite alternate}+@keyframes d-rays{from{transform:rotate(calc(var(--r) - 5deg));opacity:.5}to{transform:rotate(calc(var(--r) + 5deg));opacity:1}}+@keyframes d-dust{from{transform:translate(0,0);opacity:.2}to{transform:translate(-6px,-14px);opacity:.9}}/* ── bespoke: added demos ── */.pv-magnet{background:#08090c;display:grid;place-items:center;position:relative}@@ -1016,7 +1022,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>130 free animations · no coding needed</p>+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 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">@@ -1073,8 +1079,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 130 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 130 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 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></section><section class="how" id="how" aria-labelledby="how-title">@@ -1092,7 +1098,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">130 web animations with live demos and copyable prompts.</p>+ <p class="foot-t">131 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>@@ -1285,6 +1291,7 @@ const CATS=[['matrix-rain','Matrix Rain','Columns of glowing characters rain down a dark screen. Best for tech themes.'],['plasma','Plasma Field','Smooth waves of color flow endlessly, made from math. Best for creative sites.'],['topographic-lines','Topographic Lines','Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.'],+ ['light-rays','Light Rays','Soft beams of light fall from above and slowly sweep across. Best for hero intros.'],]}];@@ -1294,7 +1301,7 @@ const PV={'svg-line-draw':'linedraw','scrollspy-nav':'spy','scroll-background-color':'bgblend','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','topographic-lines':'topo',+ 'flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv','topographic-lines':'topo','light-rays':'rays','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',@@ -1467,7 +1474,8 @@ const PLACES={'synthwave-grid':['bg'],'matrix-rain':['bg'],'plasma':['bg'],- 'topographic-lines':['bg']+ 'topographic-lines':['bg'],+ 'light-rays':['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'];@@ -1483,6 +1491,8 @@ function pvMarkup(k){case 'sig7': return '<span class="s7 anim"></span>';case 'topo': {const ring=(cx,cy,R,k)=>{let d='';for(let i=0;i<48;i++){const a=i*.1309,r=R+(1+R*.045)*(2.2*Math.sin(2*a+1+R*.035)+1.5*Math.sin(3*a+.4-R*.05)+.8*Math.sin(5*a+2));d+=(i?'L':'M')+(cx+r*Math.cos(a)).toFixed(1)+' '+(cy+r*.8*Math.sin(a)).toFixed(1);}return '<path'+(k%4?'':' class="ix"')+' d="'+d+'Z"/>';};return '<svg viewBox="0 0 160 100"><g class="h1 anim">'+[6,13,20,27,34,41,48,55].map((R,k)=>ring(60,56,R,k+1)).join('')+'</g><g class="h2 anim">'+[5,10,15].map((R,k)=>ring(150,10,R,k+3)).join('')+'</g><g class="h3 anim">'+[5,10].map((R,k)=>ring(152,98,R,k+3)).join('')+'</g></svg>';}+ case 'rays': return [[14,6.5],[27,8],[39,7],[51,9],[62,7.5]].map(([r,d],k)=>'<i class="anim" style="--r:'+r+'deg;animation-duration:'+d+'s;animation-delay:'+(-k*1.7)+'s"></i>').join('')++ [[70,40],[54,62],[42,30],[78,70],[30,52]].map(([x,y],k)=>'<b class="anim" style="left:'+x+'%;top:'+y+'%;animation-delay:'+(-k*1.3)+'s"></b>').join('');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 6695552e..46318b52 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -131,4 +131,5 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/matrix-rain/</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/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/topographic-lines/</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/light-rays/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url></urlset>