Skip to content

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.

feat: Topographic Lines (07.21)

matin248fd18b0000
diff --git a/README.md b/README.md
index 60328023..0ca817ea 100644
--- a/README.md
+++ b/README.md
@@ -237,6 +237,7 @@ All 129 techniques, each linked to its live demo.
- **[Synthwave Grid](animations/07-ambient-background/synthwave-grid/)** — A glowing grid rolls toward you under a striped sun. Best for music and games.
- **[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.
</details>
diff --git a/animations/07-ambient-background/README.md b/animations/07-ambient-background/README.md
index 61006e59..4259fbb1 100644
--- a/animations/07-ambient-background/README.md
+++ b/animations/07-ambient-background/README.md
@@ -23,6 +23,7 @@ Passive, looping effects that hold visual interest without demanding attention.
| [Synthwave Grid](synthwave-grid/) | A glowing grid rolls toward you under a striped sun. Best for music and games. |
| [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. |
## The ambient mindset
diff --git a/animations/07-ambient-background/topographic-lines/README.md b/animations/07-ambient-background/topographic-lines/README.md
new file mode 100644
index 00000000..fe50f1ca
--- /dev/null
+++ b/animations/07-ambient-background/topographic-lines/README.md
@@ -0,0 +1,54 @@
+# Topographic Lines
+
+## What it is
+Topographic lines are the contour lines of a map, drawn over an invisible height map that slowly changes. Each line joins all the points at one height, so the lines crowd together on steep slopes and spread apart on flat ground. As the hills swell, sink and drift, the lines bend, merge and split, like a map of land that is still taking shape.
+
+## When to use it
+- Hero backgrounds for outdoor, hiking, travel and climbing brands
+- Maps, geography and data products that want a quiet, on-theme texture
+- Portfolio and studio sites that want a hand-drawn, cartographic feel
+- Section dividers or footers where a slow pattern fills empty space
+
+## How it works
+The height of every point comes from smooth noise (Perlin gradient noise): two layers of it, broad hills plus smaller bumps, each sliding slowly in its own direction, so their sum swells and sinks instead of moving in one piece. The height is sampled on a grid, 7px squares on a computer and 9px on a phone. Each frame, marching squares turns the grid into lines: for every square and every contour level between its lowest and highest corner, the level crosses the square's sides where the height equals it, and a short segment joins the crossings. A square's side is shared with its neighbor, so both find the same crossing and the segments join into continuous lines.
+
+```js
+for (let m = Math.ceil(lowest / GAP); m * GAP < highest; m++) {
+ const L = m * GAP; // this contour's height
+ const idx = (a > L ? 8 : 0) | (b > L ? 4 : 0) | (c > L ? 2 : 0) | (d > L ? 1 : 0);
+ // two opposite corners above the level: the middle of the square decides which sides join
+ const sides = SEG[idx] || ((idx === 5) === ((a + b + c + d) / 4 > L) ? [0, 3, 2, 1] : [0, 1, 3, 2]);
+ const path = BOLD && m % 5 === 0 ? bold : thin; // every fifth level is an index line
+ for (let e = 0; e < sides.length; e += 2) {
+ cross(sides[e], x, y, L, a, b, c, d); path.moveTo(px, py);
+ cross(sides[e + 1], x, y, L, a, b, c, d); path.lineTo(px, py);
+ }
+}
+
+// where level L crosses the top side: linear interpolation between the two corner heights
+px = x + step * (L - a) / (b - a); py = y;
+```
+
+The field 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 hills move at the same pace on a 30 Hz phone and a 144 Hz monitor. Every frame clears the canvas and draws the whole picture again, which also makes a setting change show at once while the loop is paused.
+
+## Key parameters
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Line spacing | Medium | How much the height changes between two lines: tight puts about 1.7 times as many lines on the same ground, wide about 0.6 times |
+| Speed | Normal | How fast the hills swell and drift: slow is half the normal pace and fast twice it; at normal the broad hills slide about 7px a second |
+| Color | Sand | Sand, mint, sky blue or white lines on a dark ground |
+| Hill size | Medium | How wide one hill is: about 130px (small), 220px (medium) or 360px (large) |
+| Bold every fifth line | on | Every fifth line is drawn thicker and brighter, like the index contours of a printed map |
+
+## Production notes
+- **Cost**: the work is the noise at every grid point plus one pass of marching squares, under a millisecond a frame on a laptop for a 960 × 380 stage. A coarser grid is the main saving; phones (up to 600px wide, or up to 500px tall for a phone held sideways) sample every 9px instead of 7px.
+- **One stroke per style**: all thin segments go into one path and all bold ones into another, so a frame is two strokes, not thousands.
+- **Smoother lines**: for a print-quality look, join the segments into polylines and draw them as curves, or render the contours in a WebGL fragment shader (the fractional part of height divided by spacing, drawn where it is near zero, with its screen-space derivative for an even line width).
+- **Libraries**: [d3-contour](https://github.com/d3/d3-contour) builds contour polygons from a grid of values with the same marching squares method; [simplex-noise](https://github.com/jwagner/simplex-noise.js) supplies the height field.
+- **Reduced motion**: the demo starts paused with the lines drawn still, until the visitor presses Play.
+- **It is decorative**: keep the canvas `aria-hidden` and place real content above it; keep the lines faint enough that text over them stays readable.
+
+## See also
+- [Flow Field](../flow-field/) — particles follow a noise field instead of tracing its heights
+- [Plasma Field](../plasma/) — a field of waves shown as smooth color instead of lines
+- [Grid / Dot Pattern Parallax](../grid-dot-pattern-parallax/) — a quiet pattern that shifts gently for depth
diff --git a/animations/07-ambient-background/topographic-lines/index.html b/animations/07-ambient-background/topographic-lines/index.html
new file mode 100644
index 00000000..168f3658
--- /dev/null
+++ b/animations/07-ambient-background/topographic-lines/index.html
@@ -0,0 +1,285 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Topographic Lines — Animation Handbook</title>
+ <meta name="description" content="Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.">
+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/topographic-lines/">
+ <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="Topographic Lines — Animation Handbook">
+ <meta property="og:description" content="Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.">
+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/topographic-lines/">
+ <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="Topographic Lines — Animation Handbook">
+ <meta name="twitter:description" content="Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.">
+ <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": "Topographic Lines", "name": "Topographic Lines", "description": "Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/topographic-lines/", "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, Topographic Lines"}</script>
+ <style>
+ :root{--ui-accent:#ffce5a}
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
+ .stage{position:relative;overflow:hidden;background:radial-gradient(ellipse at 50% 42%,#141a17,#0a0d0c 72%)}
+ canvas{display:block;width:100%;height:100%}
+ /* A soft dark edge, like the worn border of a printed map */
+ .stage::after{content:"";position:absolute;inset:0;pointer-events:none;background:radial-gradient(ellipse at center,transparent 58%,rgba(0,0,0,.5))}
+ </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="../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>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">07.21 · Ambient &amp; Background</p>
+ <h1>Topographic Lines</h1>
+ <p class="hb-lede">Contour lines like those on a hiking map slowly bend and drift. Best for outdoor brands.</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 class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="gap-lbl">Line spacing</p>
+ <div class="seg" id="gap-seg" role="group" aria-labelledby="gap-lbl">
+ <button type="button" data-gap="0.06" aria-pressed="false">Tight</button>
+ <button type="button" data-gap="0.1" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-gap="0.16" aria-pressed="false">Wide</button>
+ </div>
+ <p class="hb-hint">How much the height changes from one line to the next.</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 hills swell and drift.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="color-lbl">Color</p>
+ <div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
+ <button type="button" class="on" aria-pressed="true" aria-label="Sand" data-col="sand" style="background:#e3c89a"></button>
+ <button type="button" aria-pressed="false" aria-label="Mint" data-col="mint" style="background:#7fe3b8"></button>
+ <button type="button" aria-pressed="false" aria-label="Sky blue" data-col="sky" style="background:#8cc4ff"></button>
+ <button type="button" aria-pressed="false" aria-label="White" data-col="white" style="background:#e8e8ec"></button>
+ </div>
+ <p class="hb-hint">The color of the lines.</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="hill-lbl">Hill size</p>
+ <div class="seg" id="hill-seg" role="group" aria-labelledby="hill-lbl">
+ <button type="button" data-px="130" aria-pressed="false">Small</button>
+ <button type="button" data-px="220" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-px="360" aria-pressed="false">Large</button>
+ </div>
+ <p class="hb-hint">Small hills make busy rings; large ones make long, lazy curves.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Bold every fifth line</span><input class="hb-switch" type="checkbox" role="switch" id="bold-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">Every fifth line is drawn thicker, as on a printed map.</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 a topographic lines background to [the section you want it behind]. Build a smooth, hilly height map from layered noise and draw its contour lines on a canvas: sample the height on a grid, and in each grid square join the points where the height crosses each level, so every line follows one height, as on a hiking map. Make every fifth line bolder when the settings include it. Shift the noise slowly by elapsed time so the hills swell, shrink and drift, and redraw each frame. Sample a coarser grid on phones. If the visitor has reduced motion turned on, show the lines 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>Outdoor and travel brands</li><li>Hero sections</li><li>Maps and data products</li><li>Portfolio backgrounds</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Busy layouts</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');
+ const slowTog=document.getElementById('slow-tog');
+ const COLORS={sand:'227,200,154',mint:'127,227,184',sky:'140,196,255',white:'232,232,236'};
+ const phone=matchMedia('(max-width:600px),(max-height:500px)'); // phones and short screens sample the heights on a coarser grid
+ let W=0,H=0,raf=null,lastT=null;
+ let GAP=.1,SPD=1,COL='sand',HILL=220,BOLD=true;
+ let clock=0; // the field's own time in seconds: it moves only while the loop runs, so Play carries on with no jump
+ let step=7,cols=0,rows=0,hts=null;
+
+ // Perlin's gradient noise: a random slope at every whole point of a lattice, blended smoothly in between (about -1 to 1)
+ const P=new Uint8Array(512);
+ {const p=[...Array(256).keys()];for(let i=255;i>0;i--){const j=Math.random()*(i+1)|0;[p[i],p[j]]=[p[j],p[i]];}for(let i=0;i<512;i++)P[i]=p[i&255];}
+ const fade=t=>t*t*t*(t*(t*6-15)+10);
+ const grad=(h,x,y)=>(h&1?-x:x)+(h&2?-y:y);
+ function noise(x,y){
+ const X=Math.floor(x),Y=Math.floor(y),fx=x-X,fy=y-Y,i=X&255,j=Y&255,u=fade(fx),v=fade(fy);
+ const a=grad(P[P[i]+j],fx,fy),b=grad(P[P[i+1]+j],fx-1,fy),c=grad(P[P[i]+j+1],fx,fy-1),d=grad(P[P[i+1]+j+1],fx-1,fy-1);
+ const top=a+u*(b-a);
+ return top+v*(c+u*(d-c)-top);
+ }
+
+ // The height at every grid point: broad hills drifting one way plus smaller ones drifting another, so the ground seems to
+ // swell and sink as it moves instead of sliding past in one piece
+ function heights(){
+ const s=1/HILL,t=clock;
+ for(let r=0,k=0;r<=rows;r++){
+ const y=r*step*s;
+ for(let q=0;q<=cols;q++,k++){
+ const x=q*step*s;
+ hts[k]=noise(x+t*.03,y+t*.012)+.45*noise(x*2.3-t*.05+17.3,y*2.3+t*.03+5.1);
+ }
+ }
+ }
+
+ // Marching squares. Each grid square has a height at its four corners. Every contour level between its lowest and highest
+ // corner crosses the square's sides where the height equals it (found by linear interpolation), and a segment joins those
+ // crossings. Neighbor squares find the same crossing on the side they share, so the segments join into smooth lines.
+ // SEG lists, for each mix of corners above the level, the sides each segment joins (0 top, 1 right, 2 bottom, 3 left).
+ const SEG=[[],[3,2],[2,1],[3,1],[0,1],null,[0,2],[0,3],[0,3],[0,2],null,[0,1],[3,1],[2,1],[3,2],[]];
+ let px=0,py=0;
+ function cross(e,x,y,L,a,b,c,d){
+ if(e===0){px=x+step*(L-a)/(b-a);py=y;}
+ else if(e===1){px=x+step;py=y+step*(L-b)/(c-b);}
+ else if(e===2){px=x+step*(L-d)/(c-d);py=y+step;}
+ else{px=x;py=y+step*(L-a)/(d-a);}
+ }
+ // The whole picture at the field's current time; the canvas is cleared first, so nothing of an earlier picture stays
+ function draw(){
+ heights();
+ const thin=new Path2D(),bold=new Path2D(),n=cols+1;
+ for(let r=0;r<rows;r++)for(let q=0;q<cols;q++){
+ const k=r*n+q,a=hts[k],b=hts[k+1],c=hts[k+n+1],d=hts[k+n],x=q*step,y=r*step;
+ const hi=Math.max(a,b,c,d);
+ for(let m=Math.ceil(Math.min(a,b,c,d)/GAP);m*GAP<hi;m++){
+ const L=m*GAP,idx=(a>L?8:0)|(b>L?4:0)|(c>L?2:0)|(d>L?1:0);
+ // two opposite corners above the level: the middle of the square decides which pairs of sides join
+ const s=SEG[idx]||((idx===5)===((a+b+c+d)/4>L)?[0,3,2,1]:[0,1,3,2]);
+ const path=BOLD&&m%5===0?bold:thin;
+ for(let e=0;e<s.length;e+=2){
+ cross(s[e],x,y,L,a,b,c,d);path.moveTo(px,py);
+ cross(s[e+1],x,y,L,a,b,c,d);path.lineTo(px,py);
+ }
+ }
+ }
+ ctx.clearRect(0,0,W,H);
+ const rgb=COLORS[COL];
+ ctx.lineWidth=1;ctx.strokeStyle=`rgba(${rgb},.5)`;ctx.stroke(thin);
+ ctx.lineWidth=1.8;ctx.strokeStyle=`rgba(${rgb},.85)`;ctx.stroke(bold);
+ }
+
+ // 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 field'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;
+ clock+=dt/1000*SPD*(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 lines 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;});
+
+ // The grid the heights are sampled on: 7px squares, 9px on phones
+ function grid(){step=phone.matches?9:7;cols=Math.ceil(W/step);rows=Math.ceil(H/step);hts=new Float32Array((cols+1)*(rows+1));}
+ // Setting the canvas size wipes it, so a real change of the stage's size draws the lines 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);
+ ctx.lineCap=ctx.lineJoin='round';
+ grid();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 hills carry on from where they are, at the new pace.
+ choices('gap-seg',d=>{GAP=+d.gap;draw();});
+ choices('speed-seg',d=>{SPD=+d.spd;});
+ choices('color-sw',d=>{COL=d.col;draw();});
+ choices('hill-seg',d=>{HILL=+d.px;draw();});
+ document.getElementById('bold-tog').addEventListener('change',e=>{BOLD=e.target.checked;draw();});
+
+ resize();
+ window.addEventListener('resize',resize);
+ // A window that crosses the phone size changes the grid, even when the stage keeps its size
+ function onPhone(){if((phone.matches?9:7)!==step){grid();draw();}}
+ if(phone.addEventListener)phone.addEventListener('change',onPhone);
+ else if(phone.addListener)phone.addListener(onPhone);
+ start();
+</script>
+</body>
+</html>
diff --git a/index.html b/index.html
index e2d7eb15..6028fac2 100644
--- a/index.html
+++ b/index.html
@@ -816,6 +816,15 @@ button,input{font:inherit;color:inherit}
.pv-aripple .src b:nth-child(2){animation-delay:1.3s}.pv-aripple .src b:nth-child(3){animation-delay:2.6s}
.pv-aripple .s2 b{animation-duration:4.6s}
@keyframes d-arip{0%{transform:translate(-50%,-50%) scale(1);opacity:.8}100%{transform:translate(-50%,-50%) scale(9);opacity:0}}
+/* contour rings of one big hill and two small ones in the corners: each set turns and breathes a little around its own peak */
+.pv-topo{background:radial-gradient(ellipse at 40% 55%,#151b17,#0a0d0c 75%);overflow:hidden}
+.pv-topo svg{position:absolute;inset:0;width:100%;height:100%}
+.pv-topo path{fill:none;stroke:var(--accent);stroke-width:.55;stroke-linejoin:round;opacity:.55}
+.pv-topo path.ix{stroke-width:1.1;opacity:.95}
+.pv-topo .h1{transform-origin:60px 56px;animation:d-topo 9s ease-in-out infinite alternate}
+.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)}}
/* ── bespoke: added demos ── */
.pv-magnet{background:#08090c;display:grid;place-items:center;position:relative}
@@ -1007,7 +1016,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>129 free animations · no coding needed</p>
+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>130 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">
@@ -1064,8 +1073,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 129 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 129 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/&lt;category&gt;/&lt;name&gt;/</code>.</p></noscript>
+ <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/&lt;category&gt;/&lt;name&gt;/</code>.</p></noscript>
</section>
<section class="how" id="how" aria-labelledby="how-title">
@@ -1083,7 +1092,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">129 web animations with live demos and copyable prompts.</p>
+ <p class="foot-t">130 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>
@@ -1275,6 +1284,7 @@ const CATS=[
['synthwave-grid','Synthwave Grid','A glowing grid rolls toward you under a striped sun. Best for music and games.'],
['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.'],
]
}
];
@@ -1284,7 +1294,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',
+ 'flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv','topographic-lines':'topo',
'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',
@@ -1456,7 +1466,8 @@ const PLACES={
'flow-field':['bg'],
'synthwave-grid':['bg'],
'matrix-rain':['bg'],
- 'plasma':['bg']
+ 'plasma':['bg'],
+ 'topographic-lines':['bg']
};
// 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'];
@@ -1470,6 +1481,8 @@ function pvMarkup(k){
case 'sig5': return '<span class="s5 anim"></span><span class="s5 anim"></span><span class="s5 anim"></span>';
case 'sig6': return '<div class="cube anim"><span class="face f1"></span><span class="face f2"></span><span class="face f3"></span><span class="face f4"></span><span class="face f5"></span><span class="face f6"></span></div>';
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 '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.xml
index 23cc35d9..6695552e 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -130,4 +130,5 @@
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/synthwave-grid/</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/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>
</urlset>