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: Game of Life (07.23)

matindbbb88d9710d
diff --git a/README.md b/README.md
index 99f49f09..03156e9a 100644
--- a/README.md
+++ b/README.md
@@ -239,6 +239,7 @@ All 129 techniques, each linked to its live demo.
- **[Plasma Field](animations/07-ambient-background/plasma/)** — Smooth waves of color flow endlessly, made from math. Best for creative sites.
- **[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.
+- **[Game of Life](animations/07-ambient-background/game-of-life/)** — Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.
</details>
diff --git a/animations/07-ambient-background/README.md b/animations/07-ambient-background/README.md
index 93873882..34efe61b 100644
--- a/animations/07-ambient-background/README.md
+++ b/animations/07-ambient-background/README.md
@@ -25,6 +25,7 @@ Passive, looping effects that hold visual interest without demanding attention.
| [Plasma Field](plasma/) | Smooth waves of color flow endlessly, made from math. Best for creative sites. |
| [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. |
+| [Game of Life](game-of-life/) | Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites. |
## The ambient mindset
diff --git a/animations/07-ambient-background/game-of-life/README.md b/animations/07-ambient-background/game-of-life/README.md
new file mode 100644
index 00000000..9a085919
--- /dev/null
+++ b/animations/07-ambient-background/game-of-life/README.md
@@ -0,0 +1,50 @@
+# Game of Life
+
+## What it is
+Conway's Game of Life is a grid of square cells, each alive or dead, that changes one generation at a time by three rules about each cell's eight neighbors: a dead cell with exactly three live neighbors is born, a live cell with two or three lives on, and every other cell dies. Nobody steers it, yet out of these rules come still shapes, shapes that blink, gliders that crawl across the grid and guns that fire gliders forever. The mathematician John Conway devised it in 1970.
+
+## When to use it
+- Backgrounds for tech, science and coding sites, where emergent behavior fits the theme
+- Developer portfolios and about pages, where visitors can draw their own cells
+- Loading, idle and 404 screens that should stay alive without repeating a fixed loop
+- Teaching pages about simulation, cellular automata or complexity
+
+## How it works
+The world is two arrays of cells, one for this generation and one for the next. It reaches past the view by 16 cells on every side, so gliders fly off-screen and settle out of sight, and it has one more ring of cells that always stay dead, so every cell has eight neighbors to count and the loop needs no edge checks:
+
+```js
+for (let y = 1; y <= rows; y++) for (let i = y * S + 1, end = i + S - 2; i < end; i++) {
+ const n = cells[i - S - 1] + cells[i - S] + cells[i - S + 1] + cells[i - 1] + cells[i + 1]
+ + cells[i + S - 1] + cells[i + S] + cells[i + S + 1]; // S: cells in one row
+ const v = next[i] = n === 3 || (n === 2 && cells[i]) ? 1 : 0; // born, lives on, or dies
+ if (v) hash = (hash + Math.imul(i, 0x9E3779B1)) | 0; else if (cells[i]) glow[i] = 1; // a cell that dies starts its trail
+}
+[cells, next] = [next, cells];
+```
+
+Generations follow elapsed time, not frames. Each frame adds the time since the last one (at most 50 ms, a third of it in slow motion) to a running total, and a generation is taken for every 1/Speed of a second in it, so the world changes at the same pace on a 30 Hz phone and a 144 Hz monitor. Trails fade by time too: a dead cell's glow halves every 120 ms, `glow *= 0.5 ** (ms / 120)`. Each picture gathers the cells of one brightness into one path, so a frame is a handful of fills however many cells there are.
+
+A random world usually settles into still shapes and blinkers within a few hundred to a few thousand generations. The step adds up a hash of the live cells; when a hash comes back within 15 generations, the world is repeating itself, and after 40 such generations it starts again, with the old cells fading out as the new ones begin. The glider gun never repeats that soon (it repeats every 30 generations), so it runs forever.
+
+## Key parameters
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Speed | Normal | How many generations pass each second: slow is 4, normal 10 and fast 20 |
+| Cell size | Medium | Small cells are 6px, medium 9px and large 14px; phones draw small cells 8px wide, so the world has fewer cells to work out and draw |
+| Start pattern | Random | Random fills about 30% of the cells; the glider gun (Gosper's) fires a glider every 30 generations; the acorn is seven cells that grow for over 5,000 generations on an open grid |
+| Color | Mint | Mint, amber, sky blue or pink cells |
+| Fading trails | on | A cell that dies fades out over about half a second instead of vanishing at once |
+| Grid lines | off | Faint lines show the squares the cells live in |
+
+## Production notes
+- **Drawing on it**: Pointer Events cover mouse, touch and pen, and pointer capture keeps a stroke going outside the stage. A stroke fills every cell on the straight line between two pointer positions, so a quick stroke leaves no gaps. `touch-action: none` on the canvas lets a finger draw instead of scrolling the page; keep the stage short enough that the page can still be scrolled around it.
+- **Phones**: on phone-sized screens (up to 600px wide, or up to 500px tall for a phone held sideways) the cells are at least 8px wide.
+- **Bigger worlds**: a grid of a million cells is still fast with typed arrays; beyond that, run the rules on the GPU (two textures, each frame's shader reads one and writes the other), or use HashLife, which skips ahead through repeating regions (Golly does this).
+- **Pattern files**: patterns are shared as run-length code (RLE), as in the demo; LifeWiki and the Golly pattern collection hold thousands.
+- **Reduced motion**: the demo starts paused, showing the world a few generations in, until the visitor presses Play. Drawing still works while paused.
+- **It is decorative**: keep the canvas `aria-hidden`, dim the cells or use large ones behind text, and stop the loop when the section is off-screen.
+
+## See also
+- [Matrix Rain](../matrix-rain/) — another canvas grid that changes step by step
+- [Particle Constellation](../particle-constellation/) — dots that link up whenever they come close
+- [Flow Field](../flow-field/) — simple rules steer many particles into a living pattern
diff --git a/animations/07-ambient-background/game-of-life/index.html b/animations/07-ambient-background/game-of-life/index.html
new file mode 100644
index 00000000..6e2de246
--- /dev/null
+++ b/animations/07-ambient-background/game-of-life/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>Game of Life — Animation Handbook</title>
+ <meta name="description" content="Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.">
+ <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/game-of-life/">
+ <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="Game of Life — Animation Handbook">
+ <meta property="og:description" content="Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.">
+ <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/game-of-life/">
+ <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="Game of Life — Animation Handbook">
+ <meta name="twitter:description" content="Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.">
+ <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": "Game of Life", "name": "Game of Life", "description": "Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/game-of-life/", "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, Game of Life"}</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% 45%,#0e1214,#07090b 75%)}
+ /* the cells are drawn with a pen: a finger on the stage draws instead of scrolling the page */
+ canvas{display:block;width:100%;height:100%;touch-action:none;cursor:crosshair}
+ </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="../light-rays/" rel="prev" aria-label="Previous: Light Rays"><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>Light Rays</span></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">07.23 · Ambient &amp; Background</p>
+ <h1>Game of Life</h1>
+ <p class="hb-lede">Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.</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. Click, drag or touch it to draw new cells, or press Reset to start again.</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>
+ <button class="hb-play" type="button" id="btn-reset" data-hb-reset><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Reset</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="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-gens="4" aria-pressed="false">Slow</button>
+ <button type="button" data-gens="10" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-gens="20" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">How quickly one generation follows the next.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="size-lbl">Cell size</p>
+ <div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">
+ <button type="button" data-px="6" aria-pressed="false">Small</button>
+ <button type="button" data-px="9" class="on" aria-pressed="true">Medium</button>
+ <button type="button" data-px="14" aria-pressed="false">Large</button>
+ </div>
+ <p class="hb-hint">Smaller cells make a bigger world; on phones the small ones are a little larger.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="pattern-lbl">Start pattern</p>
+ <div class="seg" id="pattern-seg" role="group" aria-labelledby="pattern-lbl">
+ <button type="button" data-pattern="random" class="on" aria-pressed="true">Random</button>
+ <button type="button" data-pattern="gun" aria-pressed="false">Glider gun</button>
+ <button type="button" data-pattern="acorn" aria-pressed="false">Acorn</button>
+ </div>
+ <p class="hb-hint">The glider gun fires gliders forever; the acorn grows from seven cells.</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="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="Mint" data-col="mint" style="background:#5fe0a8"></button>
+ <button type="button" aria-pressed="false" aria-label="Amber" data-col="amber" style="background:#ffc55a"></button>
+ <button type="button" aria-pressed="false" aria-label="Sky blue" data-col="sky" style="background:#6ab4ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Pink" data-col="pink" style="background:#ff80a0"></button>
+ </div>
+ <p class="hb-hint">The color of the living cells.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Fading trails</span><input class="hb-switch" type="checkbox" role="switch" id="trail-tog" checked autocomplete="off"></label>
+ <p class="hb-hint">Cells that die fade out instead of vanishing at once.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Grid lines</span><input class="hb-switch" type="checkbox" role="switch" id="grid-tog" autocomplete="off"></label>
+ <p class="hb-hint">Shows the squares the cells live in.</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 Game of Life background to [the section you want it behind]. Split a canvas into a grid of square cells, each alive or dead, and at a steady pace work out the next generation from each cell's eight neighbors: a dead cell with exactly three live neighbors is born, a live cell with two or three stays alive, and every other cell dies. Time the generations by elapsed time, not by frames, and when the settings include trails, let dying cells fade out. Let the visitor click, drag or touch to draw cells, and start again when the world settles. Use larger 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>Tech and science sites</li><li>Developer portfolios</li><li>Loading and idle screens</li><li>404 pages</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Calm brands</li><li>Long reading pages</li></ul>
+ </div>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
+</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
+<script>
+ const cvs=document.getElementById('cvs'),ctx=cvs.getContext('2d');
+ const stage=document.querySelector('.stage');
+ const slowTog=document.getElementById('slow-tog');
+ const COLORS={mint:'95,224,168',amber:'255,197,90',sky:'106,180,255',pink:'255,128,160'};
+ const phone=matchMedia('(max-width:600px),(max-height:500px)'); // phones and short screens draw cells at least 8px wide
+ const M=16; // hidden cells all round the view, where gliders fly off and settle out of sight
+ const PATTERNS={gun:'24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4bobo$10bo5bo7bo$11bo3bo$12b2o!',acorn:'bo5b$3bo3b$2o2b3o!'};
+ const AHEAD={random:20,gun:120,acorn:60}; // generations run before the first picture, so it already looks alive
+ let W=0,H=0,raf=null,lastT=null,acc=0;
+ let GENS=10,CELL=9,PATTERN='random',COL='mint',TRAILS=true,GRID=false;
+ let cs=9,C=0,R=0,S=0,ox=0,oy=0,cells=null,next=null,glow=null,ring=[],stuck=0,pen=null;
+
+ // Patterns in run-length code: b is a dead cell, o a live one, $ ends a row, and a number repeats what follows it
+ function rle(s){const out=[];let x=0,y=0,n='';
+ for(const ch of s){if(ch>='0'&&ch<='9'){n+=ch;continue;}const k=+n||1;n='';if(ch==='b')x+=k;else if(ch==='o')for(let i=0;i<k;i++)out.push([x++,y]);else if(ch==='$'){y+=k;x=0;}}
+ return out;}
+ // The world: the C × R cells in view, M hidden cells on every side, and one more ring of cells that stay dead, so every
+ // cell has eight neighbors to count. at(x, y) is where the cell x across and y down in view sits in the arrays.
+ const at=(x,y)=>(M+1+y)*S+M+1+x;
+ function grid(){
+ cs=phone.matches?Math.max(CELL,8):CELL;
+ C=Math.ceil(W/cs);R=Math.ceil(H/cs);ox=Math.floor((W-C*cs)/2);oy=Math.floor((H-R*cs)/2);
+ S=C+2*M+2;const n=S*(R+2*M+2);
+ cells=new Uint8Array(n);next=new Uint8Array(n);glow=new Float32Array(n);
+ }
+ // A fresh world for the start pattern. soft (a world that settled starting again) lets the old cells fade out as it begins.
+ function seed(soft){
+ const old=soft&&TRAILS?cells.slice():null;cells.fill(0);
+ if(PATTERN==='random'){for(let y=0;y<R;y++)for(let x=0;x<C;x++)if(Math.random()<.3)cells[at(x,y)]=1;}
+ else{ // the gun sits at the top, placed so its stream of gliders crosses the middle; the acorn sits in the middle
+ const gun=PATTERN==='gun',y0=gun?1:Math.round(R/2)-1;
+ const x0=!gun?Math.round(C/2)-3:C>=38?Math.max(1,Math.min(C-37,Math.round(C/2-24-(R-10)/2))):Math.round((C-36)/2);
+ for(const [x,y] of rle(PATTERNS[PATTERN]))cells[at(x0+x,y0+y)]=1;
+ }
+ for(let i=0;i<AHEAD[PATTERN];i++)step();
+ glow.fill(0);
+ if(old)for(let i=0;i<old.length;i++)if(old[i]&&!cells[i])glow[i]=1;
+ ring=[];stuck=0;acc=0;
+ }
+ // One generation: a dead cell with exactly three live neighbors is born, a live one with two or three lives on, and every
+ // other cell dies. A cell that dies starts to glow (its trail). A world that repeats itself within 15 generations has settled.
+ function step(){
+ let h=0;
+ for(let y=1,rows=R+2*M;y<=rows;y++)for(let i=y*S+1,end=i+S-2;i<end;i++){
+ const n=cells[i-S-1]+cells[i-S]+cells[i-S+1]+cells[i-1]+cells[i+1]+cells[i+S-1]+cells[i+S]+cells[i+S+1];
+ const v=next[i]=n===3||(n===2&&cells[i])?1:0;
+ if(v)h=(h+Math.imul(i,0x9E3779B1))|0;else if(cells[i])glow[i]=1;
+ }
+ [cells,next]=[next,cells];
+ stuck=ring.includes(h)?stuck+1:0;
+ ring.push(h);if(ring.length>15)ring.shift();
+ }
+ // Trails dim by the time that passed in the world: the glow of a dead cell halves every 120 ms
+ function fadeBy(ms){const k=Math.pow(.5,ms/120);for(let i=0;i<glow.length;i++)if(glow[i])glow[i]=glow[i]<.03?0:glow[i]*k;}
+ // The whole picture: grid lines if chosen, the fading trails in three steps of brightness, then the living cells. Cells of
+ // one brightness go into one path, so a frame is a handful of fills however many cells there are.
+ function draw(){
+ ctx.clearRect(0,0,W,H);
+ if(GRID){const p=new Path2D();
+ for(let x=0;x<=C;x++){p.moveTo(ox+x*cs+.5,0);p.lineTo(ox+x*cs+.5,H);}for(let y=0;y<=R;y++){p.moveTo(0,oy+y*cs+.5);p.lineTo(W,oy+y*cs+.5);}
+ ctx.strokeStyle='rgba(255,255,255,.07)';ctx.lineWidth=1;ctx.stroke(p);}
+ const g=Math.max(.5,cs*.08),sz=cs-2*g,live=new Path2D(),dim=[new Path2D(),new Path2D(),new Path2D()];
+ for(let y=0;y<R;y++)for(let x=0,i=at(0,y);x<C;x++,i++){
+ if(cells[i])live.rect(ox+x*cs+g,oy+y*cs+g,sz,sz);
+ else if(TRAILS&&glow[i]>.03)dim[glow[i]>.5?0:glow[i]>.2?1:2].rect(ox+x*cs+g,oy+y*cs+g,sz,sz);
+ }
+ ctx.fillStyle=`rgb(${COLORS[COL]})`;
+ if(TRAILS)[.42,.24,.1].forEach((a,k)=>{ctx.globalAlpha=a;ctx.fill(dim[k]);});
+ ctx.globalAlpha=1;ctx.fill(live);
+ }
+ // 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 world's time grows by the time since the last picture (never more than 50 ms, so a background tab does not
+ // leap), or a third of it in slow motion, and a generation is due for every 1/Speed of a second of it; the first frame
+ // after a start has nothing to measure from and adds none. A world that has settled for 40 generations starts again.
+ function loop(ts){
+ raf=requestAnimationFrame(loop);
+ if(lastT!==null&&ts-lastT<16)return;
+ const dt=lastT===null?0:Math.min(ts-lastT,50),ms=dt*(slowTog.checked?1/3:1),every=1000/GENS;
+ lastT=ts;acc+=ms;
+ for(let n=0;acc>=every&&n<3;n++){step();acc-=every;}
+ acc=Math.min(acc,every);
+ if(stuck>=40)seed(true);
+ fadeBy(ms);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 world 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 adds no time
+ document.addEventListener('visibilitychange',()=>{lastT=null;});
+
+ // Setting the canvas size wipes it, so a real change of the stage's size builds the world again and draws it 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);
+ grid();seed();draw();
+ }
+
+ // Drawing: a press or a finger brings the cell under it to life, and a stroke draws every cell on the straight line from
+ // the last one, so a quick stroke leaves no gaps. Pointer Events cover mouse, touch and pen; capture keeps the stroke going
+ // when it leaves the stage. The picture is drawn at once, so drawing works while paused too.
+ function cellAt(e){const r=cvs.getBoundingClientRect();return [Math.floor((e.clientX-r.left-ox)/cs),Math.floor((e.clientY-r.top-oy)/cs)];}
+ function ink(e){
+ const [x,y]=cellAt(e),[px,py]=pen||[x,y],n=Math.max(Math.abs(x-px),Math.abs(y-py),1);
+ for(let k=0;k<=n;k++){const cx=Math.round(px+(x-px)*k/n),cy=Math.round(py+(y-py)*k/n);if(cx>=0&&cy>=0&&cx<C&&cy<R)cells[at(cx,cy)]=1;}
+ pen=[x,y];ring=[];stuck=0;draw();
+ }
+ cvs.addEventListener('pointerdown',e=>{if(!e.isPrimary||e.button!==0)return;pen=null;try{cvs.setPointerCapture(e.pointerId);}catch(_){}ink(e);});
+ cvs.addEventListener('pointermove',e=>{if(pen&&e.isPrimary)ink(e);});
+ ['pointerup','pointercancel','lostpointercapture'].forEach(t=>cvs.addEventListener(t,e=>{if(e.isPrimary)pen=null;}));
+ 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; Cell size and Start
+ // pattern start a fresh world. Speed changes no picture: the world carries on from where it is, at the new pace.
+ choices('speed-seg',d=>{GENS=+d.gens;});
+ choices('size-seg',d=>{CELL=+d.px;grid();seed();draw();});
+ choices('pattern-seg',d=>{PATTERN=d.pattern;seed();draw();});
+ choices('color-sw',d=>{COL=d.col;draw();});
+ document.getElementById('trail-tog').addEventListener('change',e=>{TRAILS=e.target.checked;draw();});
+ document.getElementById('grid-tog').addEventListener('change',e=>{GRID=e.target.checked;draw();});
+ document.getElementById('btn-reset').addEventListener('click',()=>{seed();draw();});
+ resize();
+ window.addEventListener('resize',resize);
+ // A window that crosses the phone size can change the cell size, even when the stage keeps its size
+ phone.addEventListener('change',()=>{if((phone.matches?Math.max(CELL,8):CELL)!==cs){grid();seed();draw();}});
+ start();
+</script>
+</body>
+</html>
diff --git a/animations/07-ambient-background/light-rays/index.html b/animations/07-ambient-background/light-rays/index.html
index 20d83f00..311cc42b 100644
--- a/animations/07-ambient-background/light-rays/index.html
+++ b/animations/07-ambient-background/light-rays/index.html
@@ -37,7 +37,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="../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>
+ <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><a href="../game-of-life/" rel="next" aria-label="Next: Game of Life"><span><span class="hb-dir">Next: </span>Game of Life</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.html
index 4a327968..c9f0c482 100644
--- a/index.html
+++ b/index.html
@@ -831,6 +831,18 @@ button,input{font:inherit;color:inherit}
.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}}
+/* Life on a faint 16 × 10 grid: two gliders crawl across (their four shapes take turns, and every fourth generation the glider
+ steps one cell down and right), a blinker flips, and a beehive and a block stay still */
+.pv-life{background:#07090b;overflow:hidden}
+.pv-life svg{position:absolute;inset:0;width:100%;height:100%}
+.pv-life .grid{fill:none;stroke:rgba(255,255,255,.07);stroke-width:.04}
+.pv-life rect{fill:var(--accent)}
+.pv-life .gl{animation:d-lifeg 16.8s steps(14,end) infinite}
+.pv-life .f{opacity:0;animation:d-lifef 1.2s steps(1,end) infinite}
+.pv-life .bl{opacity:0;animation:d-lifeb .6s steps(1,end) infinite}
+@keyframes d-lifeg{to{transform:translate(14px,14px)}}
+@keyframes d-lifef{0%{opacity:1}25%,100%{opacity:0}}
+@keyframes d-lifeb{0%{opacity:1}50%,100%{opacity:0}}
/* ── bespoke: added demos ── */
.pv-magnet{background:#08090c;display:grid;place-items:center;position:relative}
@@ -1022,7 +1034,7 @@ button,input{font:inherit;color:inherit}
<section class="wrap home-hero" aria-labelledby="hero-title">
<span class="float fl1" aria-hidden="true"></span><span class="float fl2" aria-hidden="true"></span><span class="float fl3" aria-hidden="true"></span>
<span class="float fl4" aria-hidden="true"></span><span class="float fl5" aria-hidden="true"></span><span class="float fl6" aria-hidden="true"></span>
- <p class="pill"><span class="pill-dot" aria-hidden="true"></span>131 free animations · no coding needed</p>
+ <p class="pill"><span class="pill-dot" aria-hidden="true"></span>132 free animations · no coding needed</p>
<h1 class="h1" id="hero-title">What do you want to animate?</h1>
<p class="sub">Pick a place, or describe it in your own words. Every animation plays live, and each one comes with a ready-made prompt for your AI assistant.</p>
<form class="search" id="search-form" role="search" action="./" method="get">
@@ -1079,8 +1091,8 @@ button,input{font:inherit;color:inherit}
<p class="empty-s">Try a simpler word, or pick one of these:</p>
<p class="pop"><button type="button" data-q="fade in">fade in</button><button type="button" data-q="typing text">typing text</button><button type="button" data-q="loading spinner">loading spinner</button><button type="button" data-q="parallax">parallax</button><button type="button" data-q="confetti">confetti</button></p>
</div>
- <div class="more" id="more"><button type="button" class="bigbtn" id="more-btn"><span id="more-label">Browse all 131 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>
- <noscript><p class="noscript">This page shows its animations with JavaScript. All 131 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/&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 132 animations</span><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M6 13l6 6 6-6"/></svg></button></div>
+ <noscript><p class="noscript">This page shows its animations with JavaScript. All 132 are still easy to reach: see the <a href="https://github.com/matinmonshizadeh/animation-handbook#categories">category list on GitHub</a> or the <a href="sitemap.xml">full sitemap</a>. Each demo is a page of its own under <code>/animations/&lt;category&gt;/&lt;name&gt;/</code>.</p></noscript>
</section>
<section class="how" id="how" aria-labelledby="how-title">
@@ -1098,7 +1110,7 @@ button,input{font:inherit;color:inherit}
<footer class="wrap foot">
<a class="brand" href="./"><svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><circle class="ring" cx="11.16" cy="20.84" r="6.1"/><circle class="ring" cx="15.12" cy="16.88" r="6.1"/><circle class="ring" cx="18.51" cy="13.49" r="6.1"/><circle class="ball" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
- <p class="foot-t">131 web animations with live demos and copyable prompts.</p>
+ <p class="foot-t">132 web animations with live demos and copyable prompts.</p>
<nav class="nav" aria-label="Footer"><a class="lnk" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener noreferrer">GitHub</a><a class="lnk" href="#top">Back to top</a></nav>
</footer>
<div class="toast" id="toast" role="status" aria-live="polite"><span class="ok" aria-hidden="true"><svg class="i" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span><span class="toast-t"></span></div>
@@ -1292,6 +1304,7 @@ const CATS=[
['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.'],
+ ['game-of-life','Game of Life','Cells live and die by simple neighbor rules, and patterns grow on their own. Best for tech sites.'],
]
}
];
@@ -1301,7 +1314,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','light-rays':'rays',
+ 'flip-card-3d':'flip3d','matrix-rain':'matrix','plasma':'plasmapv','topographic-lines':'topo','light-rays':'rays','game-of-life':'life',
'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',
@@ -1475,7 +1488,8 @@ const PLACES={
'matrix-rain':['bg'],
'plasma':['bg'],
'topographic-lines':['bg'],
- 'light-rays':['bg','intro']
+ 'light-rays':['bg','intro'],
+ 'game-of-life':['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'];
@@ -1493,6 +1507,13 @@ function pvMarkup(k){
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 'life': {const cell=([x,y])=>'<rect x="'+(x+.08)+'" y="'+(y+.08)+'" width=".84" height=".84" rx=".14"/>';
+ const PH=[[[1,0],[2,1],[0,2],[1,2],[2,2]],[[0,1],[2,1],[1,2],[2,2],[1,3]],[[2,1],[0,2],[2,2],[1,3],[2,3]],[[1,1],[2,2],[3,2],[1,3],[2,3]]];
+ const glider=(x,y,d)=>'<g transform="translate('+x+' '+y+')"><g class="gl anim" style="animation-delay:'+d+'s">'+PH.map((p,k)=>'<g class="f anim" style="animation-delay:'+(k*.3-1.2).toFixed(1)+'s">'+p.map(cell).join('')+'</g>').join('')+'</g></g>';
+ const blinker=(x,y)=>'<g class="bl anim">'+[[x-1,y],[x,y],[x+1,y]].map(cell).join('')+'</g><g class="bl anim" style="animation-delay:-.3s">'+[[x,y-1],[x,y],[x,y+1]].map(cell).join('')+'</g>';
+ let d='';for(let i=1;i<16;i++)d+='M'+i+' 0V10';for(let i=1;i<10;i++)d+='M0 '+i+'H16';
+ return '<svg viewBox="0 0 16 10"><path class="grid" d="'+d+'"/>'+glider(1,-4,0)+glider(-4,-2,-8.4)+blinker(14,5)+
+ [[13,0],[14,0],[12,1],[15,1],[13,2],[14,2],[1,7],[2,7],[1,8],[2,8]].map(cell).join('')+'</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 46318b52..95d64f53 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -132,4 +132,5 @@
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/plasma/</loc><lastmod>2026-07-14</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/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>
+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/game-of-life/</loc><lastmod>2026-10-01</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
</urlset>