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: ASCII / Halftone (06.22)
matinfce24e0a2d04
diff --git a/README.md b/README.mdindex f58a4588..4f05d168 100644--- a/README.md+++ b/README.md@@ -210,6 +210,7 @@ All 129 techniques, each linked to its live demo.- **[Morphing Blob](animations/06-3d-advanced/morphing-blob/)** — Blobs melt together, and one drop chases your pointer. Best for hero sections.- **[3D Flip Card](animations/06-3d-advanced/flip-card-3d/)** — A card turns over in 3D to show its back. Best for profile and product cards.- **[Flocking](animations/06-3d-advanced/flocking/)** — Birds swirl and turn together as one flock. Best for calm backgrounds.+- **[ASCII / Halftone](animations/06-3d-advanced/ascii-halftone/)** — A moving picture is redrawn with letters or dots. Best for retro and tech looks.</details>diff --git a/animations/06-3d-advanced/README.md b/animations/06-3d-advanced/README.mdindex 39ef9b4e..a289954a 100644--- a/animations/06-3d-advanced/README.md+++ b/animations/06-3d-advanced/README.md@@ -25,6 +25,7 @@ WebGL, shaders, particles, 3D transforms, and the performance-sensitive effects| [Morphing Blob](morphing-blob/) | Blobs melt together, and one drop chases your pointer. Best for hero sections. || [3D Flip Card](flip-card-3d/) | A card turns over in 3D to show its back. Best for profile and product cards. || [Flocking](flocking/) | Birds swirl and turn together as one flock. Best for calm backgrounds. |+| [ASCII / Halftone](ascii-halftone/) | A moving picture is redrawn with letters or dots. Best for retro and tech looks. |## Key conceptsdiff --git a/animations/06-3d-advanced/ascii-halftone/README.md b/animations/06-3d-advanced/ascii-halftone/README.mdnew file mode 100644index 00000000..faeb3b8c--- /dev/null+++ b/animations/06-3d-advanced/ascii-halftone/README.md@@ -0,0 +1,88 @@+# ASCII / Halftone++## What it is+An ASCII or halftone effect redraws a picture out of small marks on a grid. The picture is shrunk to one pixel per cell, and each cell's brightness picks a character (brighter cells get characters with more ink) or sets the size of a dot, as in a newspaper photo. Because the picture is read again every frame, it works on anything that moves: a canvas scene, a video or a webcam.++## When to use it+- Retro, terminal and hacker-style looks for tech brands and developer tools+- Music, game and event pages that want a printed or screen-like texture+- Hero images and portfolio headers that should feel made rather than photographed+- Loading or idle screens, where a moving picture turns into a pattern++## How it works+Every frame, the moving picture is drawn on a tiny hidden canvas, one pixel per cell, and read back. That canvas is made with `willReadFrequently`, so the browser keeps it in memory and reading it is cheap:++```js+const src = document.createElement('canvas');+const sctx = src.getContext('2d', { willReadFrequently: true });+src.width = cols; src.height = rows; // one pixel per cell+sctx.setTransform(dpr / cw, 0, 0, dpr / ch, 0, 0); // draw the scene in stage pixels, shrunk to the grid+scene(sctx, gridWidth, gridHeight);+const px = sctx.getImageData(0, 0, cols, rows).data;++function level(px, i) { // 0 to 1: how bright the cell is (how dark, on paper)+ const v = (0.2126 * px[i] + 0.7152 * px[i + 1] + 0.0722 * px[i + 2]) / 255;+ return paper ? 1 - v : v;+}+```++**One pattern per mark.** Drawing a character in every cell with `fillText` or `drawImage` costs one call per cell, over 9,000 a frame at fine detail. Instead, each mark is drawn once on a tile the size of one cell and turned into a repeating pattern. A run of neighboring cells that share a mark becomes one rectangle, and each mark's rectangles are filled in one go, so a frame is about ten fills:++```js+const RAMP = ' .-:*+=xo#'; // from no ink to the most ink+pats = [...RAMP].map(c => {+ const tile = document.createElement('canvas'), g = tile.getContext('2d');+ tile.width = cw; tile.height = ch; // one cell, in device pixels+ g.font = `600 ${ch}px "Schibsted Grotesk"`; g.textAlign = 'center'; g.textBaseline = 'middle';+ g.fillStyle = '#fff'; g.fillText(c, cw / 2, ch * 0.55);+ return ctx.createPattern(tile, 'repeat'); // repeats every cell, so it lines up with the grid+});++const top = pats.length - 1, runs = pats.map(() => new Path2D());+for (let j = 0; j < rows; j++) {+ let from = 0, run = 0;+ for (let k = 0; k <= cols; k++) {+ const n = k < cols ? Math.round(level(px, (j * cols + k) * 4) * top) : 0;+ if (n === run) continue;+ if (run) runs[run].rect(from * cw, j * ch, (k - from) * cw, ch);+ from = k; run = n;+ }+}+for (let n = 1; n <= top; n++) { ctx.fillStyle = pats[n]; ctx.fill(runs[n]); }+```++Dots work the same way: twelve tiles hold dots whose area grows evenly from none to one that fills the cell, which is what makes a halftone look right (the eye reads the share of ink, not the radius).++**Color in one step.** The marks are drawn in white on a clear canvas. Then `source-in` paints only where marks already are: with one color, or with the tiny picture itself stretched over the grid without smoothing, so every mark takes the color of its own cell:++```js+ctx.globalCompositeOperation = 'source-in';+if (fullColor) { ctx.imageSmoothingEnabled = false; ctx.drawImage(src, 0, 0, cols * cw, rows * ch); }+else { ctx.fillStyle = ink; ctx.fillRect(0, 0, cvs.width, cvs.height); }+ctx.globalCompositeOperation = 'source-over';+```++The characters are drawn with the site font. Its glyphs are not all the same width, so the ramp uses only characters narrower than a cell (a wide `@` or `%` would be cut off at the tile's edge), ordered by the ink each one measured. The scene's clock moves by the time since the last frame, at most 50 ms, and by a third of it in slow motion.++## Key parameters+| Parameter | Default | Effect |+|-----------|---------|--------|+| Drawn with | Letters | Letters gives each cell one of ten characters, from a space to a hash sign, by its brightness; dots gives it one of twelve dot sizes, from none to one that fills the cell |+| Detail | Medium | The height of a cell: fine is 8px, medium 11px and coarse 16px, and phones use 10, 14 and 20px; letter cells are 0.7 as wide as they are tall, dot cells are square |+| Colors | One color | One color paints every mark mint green, or near-black on paper; full color gives each mark the color of its spot in the picture |+| Shows the original picture | off | Draws the moving picture at 40% under the marks, so you can see what each mark stands for |+| Light paper | off | A light page with dark marks: each cell's darkness, not its brightness, picks the mark, as in a printed photo |++## Production notes+- **Count the calls, not the cells**: one `drawImage` per cell cost 36 ms a frame at fine detail in a software-rendered test; the pattern fills above draw the same frame in about 4 ms, whatever the detail.+- **Video and webcam**: draw the `<video>` into the tiny canvas each frame instead of a scene. A video from another site needs CORS headers, or reading its pixels throws a security error.+- **Glyphs and fonts**: with a monospace font every character has the same width and any ramp fits; with a proportional font, measure the characters and keep the ones narrower than a cell.+- **WebGL**: for full-screen effects at high resolution, do it in a fragment shader with a texture of characters. three.js ships an `AsciiEffect` and a `DotScreenShader`; the postprocessing library has ASCII and dot-screen effects.+- **CSS only**: a still halftone can be a dot pattern made with `radial-gradient` and masked by the image, without any script.+- **Accessibility**: the marks hide the picture's detail, so put its meaning in text (alt text or an `aria-label`), and keep the effect for decoration.+- **Reduced motion**: show one still frame; the demo starts paused with the full picture drawn.++## See also+- [Matrix Rain](../../07-ambient-background/matrix-rain/) — falling characters as a moving background+- [Image Distortion on Hover](../image-distortion-hover/) — another way to restyle a picture as it moves+- [Grain / Film Noise Overlay](../../07-ambient-background/grain-overlay/) — a fine texture laid over a picturediff --git a/animations/06-3d-advanced/ascii-halftone/index.html b/animations/06-3d-advanced/ascii-halftone/index.htmlnew file mode 100644index 00000000..05c61d5a--- /dev/null+++ b/animations/06-3d-advanced/ascii-halftone/index.html@@ -0,0 +1,288 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>ASCII / Halftone — Animation Handbook</title>+ <meta name="description" content="A moving picture is redrawn with letters or dots. Best for retro and tech looks.">+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/ascii-halftone/">+ <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="ASCII / Halftone — Animation Handbook">+ <meta property="og:description" content="A moving picture is redrawn with letters or dots. Best for retro and tech looks.">+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/ascii-halftone/">+ <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="ASCII / Halftone — Animation Handbook">+ <meta name="twitter:description" content="A moving picture is redrawn with letters or dots. Best for retro and tech looks.">+ <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": "ASCII / Halftone", "name": "ASCII / Halftone", "description": "A moving picture is redrawn with letters or dots. Best for retro and tech looks.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/ascii-halftone/", "inLanguage": "en", "articleSection": "3D & Advanced", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, 3D & Advanced, ASCII / Halftone"}</script>+ <style>+ :root{--ui-accent:#3fd6c4;--night:#07080c;--paper:#f1eadb;--ink-dark:#86e8c1;--ink-paper:#1f1c27}+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}+ .stage{position:relative;overflow:hidden;background:var(--night)}+ .stage.paper{background:var(--paper)}+ canvas{position:absolute;inset:0;display:block;width:100%;height:100%}+ #pic{opacity:.4}+ </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="../flocking/" rel="prev" aria-label="Previous: Flocking"><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>Flocking</span></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">06.22 · 3D & Advanced</p>+ <h1>ASCII / Halftone</h1>+ <p class="hb-lede">A moving picture is redrawn with letters or dots. Best for retro and tech looks.</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 at the letters, or turn on slow motion.</p></div>+ </div>+ <div class="stage" id="stage">+ <canvas id="pic" aria-hidden="true" hidden></canvas>+ <canvas id="cvs" role="img" aria-label="An evening scene with a sun and rolling hills, redrawn out of letters or dots of different sizes"></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="mode-lbl">Drawn with</p>+ <div class="seg" id="mode-seg" role="group" aria-labelledby="mode-lbl">+ <button type="button" data-mode="letters" class="on" aria-pressed="true">Letters</button>+ <button type="button" data-mode="dots" aria-pressed="false">Dots</button>+ </div>+ <p class="hb-hint">Brighter spots get letters with more ink, or bigger dots.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="detail-lbl">Detail</p>+ <div class="seg" id="detail-seg" role="group" aria-labelledby="detail-lbl">+ <button type="button" data-detail="fine" aria-pressed="false">Fine</button>+ <button type="button" data-detail="medium" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-detail="coarse" aria-pressed="false">Coarse</button>+ </div>+ <p class="hb-hint">Smaller letters or dots show more of the picture; phones use bigger ones.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="color-lbl">Colors</p>+ <div class="seg" id="color-seg" role="group" aria-labelledby="color-lbl">+ <button type="button" data-color="mono" class="on" aria-pressed="true">One color</button>+ <button type="button" data-color="full" aria-pressed="false">Full color</button>+ </div>+ <p class="hb-hint">One color looks like an old screen; full color keeps the picture's colors.</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">+ <label class="hb-switch-row"><span>Shows the original picture</span><input class="hb-switch" type="checkbox" role="switch" id="orig-tog" autocomplete="off"></label>+ <p class="hb-hint">Lays the moving picture faintly under the letters or dots.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Light paper</span><input class="hb-switch" type="checkbox" role="switch" id="paper-tog" autocomplete="off"></label>+ <p class="hb-hint">Prints dark marks on light paper, like a newspaper photo.</p>+ </div>+ </div>+ </details>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add an ASCII and halftone effect to [the picture or video you want to restyle]. Each frame, draw the picture onto a small hidden canvas with one pixel for every cell of a grid, and read back each pixel's brightness. On the visible canvas, draw a character in every cell, choosing characters with more ink for brighter cells, or draw a dot whose size grows with the brightness, like a printed photo. Color the marks with the picture's own colors or with one color. Copy the characters from a ready-made sheet instead of typing each one, so it stays smooth, and use bigger cells on phones. If the visitor has reduced motion turned on, show one still frame. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Retro and tech sites</li><li>Music and game pages</li><li>Hero images</li><li>Portfolio headers</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Photos people must see clearly</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 pic=document.getElementById('pic'),pctx=pic.getContext('2d');+const stage=document.getElementById('stage');+const slowTog=document.getElementById('slow-tog');+const css=getComputedStyle(document.documentElement),INK={dark:css.getPropertyValue('--ink-dark'),paper:css.getPropertyValue('--ink-paper')};+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+// Phones are screens up to 600px wide, or up to 500px tall when held sideways: they get bigger cells+const phone=matchMedia('(max-width:600px),(max-height:500px)');+const RAMP=' .-:*+=xo#'; // from no ink to the most ink, measured in the site font; each fits in its cell+const DOTS=12; // dot sizes, from none to one that fills its cell+const CELLS={fine:[8,10],medium:[11,14],coarse:[16,20]}; // the height of a cell in px: [other screens, phones]+// The picture is drawn into src at one pixel per cell and read back every frame+const src=document.createElement('canvas'),sctx=src.getContext('2d',{willReadFrequently:true});+// The marks are drawn in device pixels, cw × ch per cell; pats[n] repeats mark n (a character or a dot size) once per cell+let W=0,H=0,dpr=1,cw=8,ch=11,cols=1,rows=1,pats=[],t=4,raf=null,lastT=null;+let MODE='letters',DETAIL='medium',COLOR='mono',ORIG=false,PAPER=false;++// The moving picture at time t (seconds): an evening sky that is brightest at the horizon, a glowing sun that bobs, two+// drifting clouds and three rows of dark hills that slide by at their own speeds. It is drawn in stage pixels, w × h, on+// either canvas: the tiny one that is read and the full-size one shown under the marks.+function scene(g,w,h){+ const sky=g.createLinearGradient(0,0,0,h*.7);+ sky.addColorStop(0,'#0a0f2c');sky.addColorStop(.55,'#3a2c72');sky.addColorStop(1,'#ff9a7a');+ g.fillStyle=sky;g.fillRect(0,0,w,h);+ const sx=w*.66,sy=h*(.46+.04*Math.sin(t*.7)),sr=h*.16;+ let gr=g.createRadialGradient(sx,sy,0,sx,sy,h*.55);+ gr.addColorStop(0,'rgba(255,190,130,.5)');gr.addColorStop(1,'rgba(255,190,130,0)');+ g.fillStyle=gr;g.fillRect(0,0,w,h);+ gr=g.createRadialGradient(sx,sy,0,sx,sy,sr);+ gr.addColorStop(0,'#fffbe8');gr.addColorStop(.75,'#ffd47e');gr.addColorStop(1,'#ffa25c');+ g.fillStyle=gr;g.beginPath();g.arc(sx,sy,sr,0,Math.PI*2);g.fill();+ g.fillStyle='rgba(255,255,255,.22)';+ for(const [y,s,o] of [[.17,.02,0],[.29,.032,.6]]){const x=((o+t*s)%1.4-.2)*w;g.beginPath();g.ellipse(x,h*y,w*.14,h*.045,0,0,Math.PI*2);g.fill();}+ for(const [base,amp,speed,col] of [[.62,.06,.02,'#5a4890'],[.74,.07,.05,'#1d3d50'],[.87,.06,.11,'#070f14']]){+ g.fillStyle=col;g.beginPath();g.moveTo(0,h);+ for(let i=0;i<=40;i++){const p=i/40*6.3+t*speed*6.3;g.lineTo(w*i/40,h*(base+amp*(Math.sin(p)*.7+Math.sin(p*2.3+1)*.3)));}+ g.lineTo(w,h);g.fill();+ }+}++// How bright the cell at pixel offset i of the tiny picture is, 0 to 1 (how dark it is, on paper)+function level(px,i){const v=(.2126*px[i]+.7152*px[i+1]+.0722*px[i+2])/255;return PAPER?1-v:v;}+// One frame: the picture is drawn at one pixel per cell and read back. Each cell's level picks a mark, all drawn in white: a run+// of cells with the same mark is one rectangle filled with that mark's pattern, so a frame is a few fills, not one per cell.+// Then source-in paints every mark at once, in one color or in the cell's own color from the tiny picture stretched over the grid.+function render(){+ const gw=cols*cw/dpr,gh=rows*ch/dpr; // the grid in stage pixels (it may reach a little past the right and bottom edges)+ sctx.setTransform(dpr/cw,0,0,dpr/ch,0,0);scene(sctx,gw,gh);+ const px=sctx.getImageData(0,0,cols,rows).data,top=pats.length-1,runs=pats.map(()=>new Path2D());+ for(let j=0;j<rows;j++){+ let from=0,run=0;+ for(let k=0;k<=cols;k++){+ const n=k<cols?Math.round(level(px,(j*cols+k)*4)*top):0;+ if(n===run)continue;+ if(run)runs[run].rect(from*cw,j*ch,(k-from)*cw,ch);+ from=k;run=n;+ }+ }+ ctx.clearRect(0,0,cvs.width,cvs.height);+ for(let n=1;n<=top;n++){ctx.fillStyle=pats[n];ctx.fill(runs[n]);}+ ctx.globalCompositeOperation='source-in';+ if(COLOR==='full'){ctx.imageSmoothingEnabled=false;ctx.drawImage(src,0,0,cols*cw,rows*ch);}+ else{ctx.fillStyle=PAPER?INK.paper:INK.dark;ctx.fillRect(0,0,cvs.width,cvs.height);}+ ctx.globalCompositeOperation='source-over';+ if(ORIG){pctx.setTransform(dpr,0,0,dpr,0,0);scene(pctx,gw,gh);}+}++// The grid for the chosen detail, in device pixels: letters are narrower than they are tall, dots sit in square cells. Each+// mark is drawn once on a tile of one cell, which becomes a pattern repeating every cell: a character in the site font, or a+// dot whose area grows evenly from none to one that fills the cell.+function layout(){+ const letters=MODE==='letters';+ ch=Math.max(2,Math.round(CELLS[DETAIL][phone.matches?1:0]*dpr));cw=letters?Math.round(ch*.7):ch;+ cols=Math.ceil(cvs.width/cw);rows=Math.ceil(cvs.height/ch);src.width=cols;src.height=rows;+ pats=Array.from({length:letters?RAMP.length:DOTS},(_,n)=>{+ const tile=document.createElement('canvas'),g=tile.getContext('2d');+ tile.width=cw;tile.height=ch;g.fillStyle='#fff';+ if(letters){+ g.font=`600 ${ch}px "Schibsted Grotesk",system-ui,sans-serif`;+ g.textAlign='center';g.textBaseline='middle';g.fillText(RAMP[n],cw/2,ch*.55);+ }else{g.beginPath();g.arc(cw/2,ch/2,cw/2*Math.sqrt(n/(DOTS-1)),0,Math.PI*2);g.fill();}+ return ctx.createPattern(tile,'repeat');+ });+}++// loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again. At most one frame per+// 16 ms. The picture's clock moves by the time since the last frame (a third of it in slow motion), never more than 50 ms,+// so a background tab does not leap; the first frame after a start has nothing to measure from and moves nothing.+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;+ t+=dt/1000*(slowTog.checked?1/3:1);+ render();+}+function start(){if(raf)return;lastT=null;raf=requestAnimationFrame(loop);}++// Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses the+// loop on arrival, which this listener must catch. The picture on screen stays as it is while paused.+document.addEventListener('hb:pause',e=>{+ 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 moves nothing+document.addEventListener('visibilitychange',()=>{lastT=null;});++// Setting the canvas size wipes it, so a real change of the stage's size draws the picture again at once, playing or+// paused. A resize that leaves the stage as it was (a phone's address bar sliding in or out) does nothing.+function resize(){+ const w=stage.clientWidth,h=stage.clientHeight;+ if(w===W&&h===H)return;+ W=w;H=h;dpr=Math.min(window.devicePixelRatio||1,2);+ for(const c of [cvs,pic]){c.width=Math.round(W*dpr);c.height=Math.round(H*dpr);}+ layout();render();+}++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);+ }));+}+// Every setting draws the picture again at once, so the change shows while paused too+choices('mode-seg',d=>{MODE=d.mode;layout();render();});+choices('detail-seg',d=>{DETAIL=d.detail;layout();render();});+choices('color-seg',d=>{COLOR=d.color;render();});+document.getElementById('orig-tog').addEventListener('change',e=>{ORIG=e.target.checked;pic.hidden=!ORIG;render();});+document.getElementById('paper-tog').addEventListener('change',e=>{PAPER=e.target.checked;stage.classList.toggle('paper',PAPER);render();});++resize();+window.addEventListener('resize',resize);+const regrid=()=>{layout();render();};+if(phone.addEventListener)phone.addEventListener('change',regrid);+else if(phone.addListener)phone.addListener(regrid);+// The characters are drawn with the site font, which loads on demand: the sheet is drawn again once it has arrived+if(document.fonts&&document.fonts.load)document.fonts.load('600 16px "Schibsted Grotesk"').then(regrid,()=>{});+start();+</script>+</body>+</html>diff --git a/animations/06-3d-advanced/flocking/index.html b/animations/06-3d-advanced/flocking/index.htmlindex ab3a1c7d..8abc4935 100644--- a/animations/06-3d-advanced/flocking/index.html+++ b/animations/06-3d-advanced/flocking/index.html@@ -32,7 +32,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="../flip-card-3d/" rel="prev" aria-label="Previous: 3D Flip Card"><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>3D Flip Card</span></a></span>+ <span class="hb-pager"><a href="../flip-card-3d/" rel="prev" aria-label="Previous: 3D Flip Card"><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>3D Flip Card</span></a><a href="../ascii-halftone/" rel="next" aria-label="Next: ASCII / Halftone"><span><span class="hb-dir">Next: </span>ASCII / Halftone</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 8363d544..62a8a886 100644--- a/index.html+++ b/index.html@@ -785,6 +785,23 @@ button,input{font:inherit;color:inherit}@keyframes d-flock{from{transform:translate(-50%,-50%) rotate(0)}to{transform:translate(-50%,-50%) rotate(360deg)}}@keyframes d-fkj{from{transform:translate(-2px,-1px)}to{transform:translate(2px,2px)}}@media(max-width:600px){.pv-flock i{width:5px;height:6.5px;margin:-3px 0 0 -2.5px}}+.pv-ascii{background:linear-gradient(#0a0f2c,#33276a 66%);overflow:hidden;font:700 12px/1.05 var(--disp);letter-spacing:.12em}+.pv-ascii .sun{position:absolute;left:58%;top:18%;height:58%;aspect-ratio:1;animation:d-asun 6s ease-in-out infinite alternate}+.pv-ascii .lt{position:absolute;display:flex;flex-direction:column;align-items:center;justify-content:center;white-space:nowrap;animation:d-alt 7s ease-in-out infinite}+.pv-ascii .sun .lt,.pv-ascii .sun .dt{inset:0}+.pv-ascii .sun .lt{color:#ffcf7a}+.pv-ascii .dt{position:absolute;opacity:0;animation:d-adt 7s ease-in-out infinite}+.pv-ascii .dt i{position:absolute;inset:0;background:radial-gradient(circle closest-side,#ffcf7a var(--s),transparent calc(var(--s) + 12%)) 50% 50%/9px 9px}+.pv-ascii .d1{--s:78%;-webkit-mask:radial-gradient(circle closest-side,#000 40%,transparent 41%);mask:radial-gradient(circle closest-side,#000 40%,transparent 41%)}+.pv-ascii .d2{--s:52%;-webkit-mask:radial-gradient(circle closest-side,transparent 40%,#000 41% 66%,transparent 67%);mask:radial-gradient(circle closest-side,transparent 40%,#000 41% 66%,transparent 67%)}+.pv-ascii .d3{--s:28%;-webkit-mask:radial-gradient(circle closest-side,transparent 66%,#000 67% 92%,transparent 93%);mask:radial-gradient(circle closest-side,transparent 66%,#000 67% 92%,transparent 93%)}+.pv-ascii .gr{position:absolute;left:0;right:0;top:66%;bottom:0;background:radial-gradient(circle closest-side,#262d44 32%,transparent 46%) 0 0/9px 9px,#090b12}+.pv-ascii .hz{left:0;right:0;top:calc(66% - 7px);height:9px;color:#e7798c;overflow:hidden}+.pv-ascii .hz.dt{background:radial-gradient(circle closest-side,#e7798c 55%,transparent 67%) 0 0/9px 9px}+@keyframes d-asun{from{transform:translateY(-4%)}to{transform:translateY(10%)}}+@keyframes d-alt{0%,42%{opacity:1}50%,92%{opacity:0}100%{opacity:1}}+@keyframes d-adt{0%,42%{opacity:0}50%,92%{opacity:1}100%{opacity:0}}+@media(max-width:600px){.pv-ascii{font-size:7px}.pv-ascii .dt i,.pv-ascii .hz.dt,.pv-ascii .gr{background-size:6px 6px}.pv-ascii .hz{top:calc(66% - 4px);height:6px}}/* ── bespoke: 07 Ambient & Background ── */.pv-grain2{background:radial-gradient(circle at 50% 40%,#1a1710,#08080a);overflow:hidden}@@ -1013,7 +1030,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">@@ -1070,8 +1087,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">@@ -1089,7 +1106,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>@@ -1258,6 +1275,7 @@ const CATS=[['morphing-blob','Morphing Blob','Blobs melt together, and one drop chases your pointer. Best for hero sections.'],['flip-card-3d','3D Flip Card','A card turns over in 3D to show its back. Best for profile and product cards.'],['flocking','Flocking','Birds swirl and turn together as one flock. Best for calm backgrounds.'],+ ['ascii-halftone','ASCII / Halftone','A moving picture is redrawn with letters or dots. Best for retro and tech looks.'],]},{@@ -1291,7 +1309,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','flocking':'flock','matrix-rain':'matrix','plasma':'plasmapv',+ 'flip-card-3d':'flip3d','flocking':'flock','ascii-halftone':'ascii','matrix-rain':'matrix','plasma':'plasmapv','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',@@ -1447,6 +1465,7 @@ const PLACES={'morphing-blob':['bg'],'flip-card-3d':['imgcard'],'flocking':['bg'],+ 'ascii-halftone':['imgcard','bg'],// 07'animated-gradient-background':['bg'],'mesh-gradient':['bg'],@@ -1478,6 +1497,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 'flock': return '<span class="fk anim">'+[[0,18,0],[-10,6,-.3],[9,5,-.7],[-20,-5,-1.1],[1,-4,-.5],[17,-8,-.9],[-8,-17,-.2],[10,-20,-1.2],[-1,-29,-.6]].map(function(b){return '<i class="anim" style="--x:'+b[0]+'%;--y:'+b[1]+'%;--d:'+b[2]+'s"></i>';}).join('')+'</span>';+ case 'ascii': return '<span class="sun anim"><span class="lt anim">'+['.-:-.',':+xox+:','-+o###o+-',':x#####x:','-+o###o+-',':+xox+:','.-:-.'].map(function(r){return '<b>'+r+'</b>';}).join('')+'</span><span class="dt anim"><i class="d1"></i><i class="d2"></i><i class="d3"></i></span></span>'++ '<span class="gr"></span><span class="hz lt anim">'+'+='.repeat(24)+'</span><span class="hz dt anim"></span>';case 'sig7': return '<span class="s7 anim"></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>';@@ -1755,7 +1776,7 @@ let shown=[];// under the place label or between two states). Nothing here runs without reduced motion.const STILL={cover:.1,curtain:.6,kinetic:.25,carousel:.1,typewriter:.55,textclip:.7,svgpath:.7,smoke:.3,leak:.7,- flash:.41,blurpage:.2,toggle:.7,shake:.8+ flash:.41,blurpage:.2,toggle:.7,shake:.8,ascii:.2};function hold(card){const anims=card.querySelector('.pv').getAnimations({subtree:true});diff --git a/sitemap.xml b/sitemap.xmlindex b4047930..960ce6c1 100644--- a/sitemap.xml+++ b/sitemap.xml@@ -114,6 +114,7 @@<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/morphing-blob/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/flip-card-3d/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url><url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/flocking/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/ascii-halftone/</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/animated-gradient-background/</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/mesh-gradient/</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/aurora/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>