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.

23.7 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Flow Field — Animation Handbook</title>
  <meta name="description" content="Particles ride invisible currents, leaving fading trails. Best for art pages.">
  <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/flow-field/">
  <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="Flow Field — Animation Handbook">
  <meta property="og:description" content="Particles ride invisible currents, leaving fading trails. Best for art pages.">
  <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/flow-field/">
  <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="Flow Field — Animation Handbook">
  <meta name="twitter:description" content="Particles ride invisible currents, leaving fading trails. Best for art pages.">
  <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": "Flow Field", "name": "Flow Field", "description": "Particles ride invisible currents, leaving fading trails. Best for art pages.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/07-ambient-background/flow-field/", "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, Flow Field"}</script>
  <style>
    :root{--ui-accent:#ffce5a}
    *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
    .stage{position:relative;overflow:hidden;background:#05060a}
    canvas{display:block;width:100%;height:100%}
    /* See inside and Compare: a second canvas over the picture for the current's arrows, and plain words over the picture */
    .field,.lbl{display:none}
    .field{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
    .lbl{position:absolute;padding:4px 9px;border-radius:999px;background:rgba(5,6,10,.88);color:#f4f4f2;font:600 13px/1.2 var(--hb-font);white-space:nowrap}
    .stage[data-hb-mode="inside"] .field,.stage[data-hb-mode="inside"] .fl,.stage[data-hb-mode="compare"] .side{display:block}
    .fl.what{left:10px;top:10px}
    .fl.how{left:10px;bottom:10px}
    .side{top:10px}
    .side.first{left:10px}
    .side.second{left:calc(50% + 10px)}
    @media(max-width:360px){.lbl{font-size:12px;padding:3px 7px}.side.second{left:calc(50% + 6px)}}
  </style>
  <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
  <script src="../../../assets/js/demo-page.js?v=11" 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="../particle-constellation/" rel="prev" aria-label="Previous: Particle Constellation"><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>Particle Constellation</span></a><a href="../synthwave-grid/" rel="next" aria-label="Next: Synthwave Grid"><span><span class="hb-dir">Next: </span>Synthwave Grid</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
  <a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
  <header class="hb-head">
    <p class="hb-cat">07.14 · Ambient &amp; Background</p>
    <h1>Flow Field</h1>
    <p class="hb-lede">Particles ride invisible currents, leaving fading trails. Best for art pages.</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="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
      <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
      <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
      <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
    </div>
    <div class="stage">
      <canvas id="cvs" aria-hidden="true"></canvas>
      <canvas class="field" id="field" aria-hidden="true"></canvas>
      <p class="lbl fl what" aria-hidden="true" data-hb-caption>Arrows: the hidden current</p>
      <p class="lbl fl how" aria-hidden="true" data-hb-caption>Each particle follows the arrow under it</p>
      <p class="lbl side first" aria-hidden="true" data-hb-caption>Random each step</p>
      <p class="lbl side second" aria-hidden="true" data-hb-caption>Follows the current</p>
    </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>
    <div class="hb-mode-notes" aria-live="polite">
      <p data-hb-for="inside" hidden>Inside, the arrows show the invisible current: at every spot it points one way and turns slowly over time, and each particle follows the arrow under it.</p>
      <p data-hb-for="compare" hidden>On the left, Random each step: each particle picks a new direction every step, so it only scribbles in place. On the right, Follows the current: the particles ride smooth streams.</p>
    </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="scale-lbl">Swirl size</p>
        <div class="seg" id="scale-seg" role="group" aria-labelledby="scale-lbl">
          <button type="button" data-px="20" aria-pressed="false">Small</button>
          <button type="button" data-px="34" class="on" aria-pressed="true">Medium</button>
          <button type="button" data-px="60" aria-pressed="false">Large</button>
        </div>
        <p class="hb-hint">Large swirls look calm; small ones look stormy.</p>
      </div>
      <div class="hb-setting">
        <p class="hb-setting-name" id="trail-lbl">Trail length</p>
        <div class="seg" id="trail-seg" role="group" aria-labelledby="trail-lbl">
          <button type="button" data-fade="0.12" aria-pressed="false">Short</button>
          <button type="button" data-fade="0.06" class="on" aria-pressed="true">Medium</button>
          <button type="button" data-fade="0.04" aria-pressed="false">Long</button>
        </div>
        <p class="hb-hint">How long each particle's trail lingers.</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.6" aria-pressed="false">Slow</button>
          <button type="button" data-spd="1" class="on" aria-pressed="true">Normal</button>
          <button type="button" data-spd="1.6" aria-pressed="false">Fast</button>
        </div>
        <p class="hb-hint">How fast each particle moves.</p>
      </div>
    </div>
    <details class="hb-options">
      <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
      <div class="hb-settings">
        <div class="hb-setting">
          <p class="hb-setting-name" id="count-lbl">Number of particles</p>
          <div class="seg" id="count-seg" role="group" aria-labelledby="count-lbl">
            <button type="button" data-n="400" aria-pressed="false">Few</button>
            <button type="button" data-n="900" class="on" aria-pressed="true">Medium</button>
            <button type="button" data-n="1500" aria-pressed="false">Many</button>
          </div>
          <p class="hb-hint">More particles fill the currents; phones show at most 500.</p>
        </div>
        <div class="hb-setting">
          <p class="hb-setting-name" id="color-lbl">Color</p>
          <div class="seg" id="color-seg" role="group" aria-labelledby="color-lbl">
            <button type="button" data-col="mint" class="on" aria-pressed="true">Mint</button>
            <button type="button" data-col="ember" aria-pressed="false">Ember</button>
            <button type="button" data-col="ice" aria-pressed="false">Ice</button>
            <button type="button" data-col="spectrum" aria-pressed="false">Rainbow</button>
          </div>
          <p class="hb-hint">Rainbow changes color across the stage and over time.</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 flow field background to [the section you want it behind]. Fill a canvas with many particles and give every point a direction that changes smoothly from spot to spot (smooth random noise does this). Each frame, move each particle a small step along the direction under it, scaled by the time since the last frame so it runs at the same speed on every screen. Instead of clearing the canvas, cover it with a see-through dark layer once for every 60th of a second that passes, so each particle leaves a fading trail. Let the directions change slowly over time, and use fewer particles on phones. If the visitor has reduced motion turned on, show one still frame of trails. 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>
    <div class="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></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>Art and creative sites</li><li>Hero sections</li><li>Loading screens</li><li>Data art</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="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><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 PHONE_PARTS=500; // phones and short screens draw at most this many particles
  const phone=matchMedia('(max-width:600px),(max-height:500px)');
  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
  let W=0,H=0,raf=null,lastT=null,fa=0,paused=false,unseen=false,t=0; // fa: the part of a dim not yet applied
  let COUNT=900,SCALE=34,SPD=1.0,TRAIL=0.06,COL='mint';
  let parts=[];
  // See inside and Compare: the arrows' canvas, a copy of Normal's picture (with its particles and the current's time) kept while
  // Compare shows, and one arrow per 28px square
  const field=document.getElementById('field'),fctx=field.getContext('2d');
  const keep=document.createElement('canvas'),kctx=keep.getContext('2d');
  const GRID=28;
  let mode='normal',kept=null,keptT=0,ra=0; // ra: the time the random half has not yet stepped, in 60ths of a second (see frame)

  // tiny deterministic value-noise: hash a lattice, smooth-interpolate, return an angle.
  function hash(x,y){const s=Math.sin(x*127.1+y*311.7)*43758.5453;return s-Math.floor(s);}
  function smooth(t){return t*t*(3-2*t);}
  function vnoise(x,y){
    const xi=Math.floor(x),yi=Math.floor(y),xf=x-xi,yf=y-yi;
    const tl=hash(xi,yi),tr=hash(xi+1,yi),bl=hash(xi,yi+1),br=hash(xi+1,yi+1);
    const u=smooth(xf),v=smooth(yf);
    return (tl*(1-u)+tr*u)*(1-v)+(bl*(1-u)+br*u)*v;
  }
  function angleAt(x,y,time){
    const n=vnoise(x/SCALE,y/SCALE+time*0.15);
    return n*Math.PI*4; // map [0,1] noise to a couple of full turns
  }

  // In Compare the particles split in two: the first half lives in the left half of the canvas and the second in the right (on
  // phones each half gets half the phone's particles). Elsewhere every particle may go anywhere, as before.
  function init(){
    const n=phone.matches?Math.min(COUNT,PHONE_PARTS):COUNT,split=mode==='compare';
    parts=Array.from({length:n},(_,i)=>{
      const side=split&&i>=n/2?1:0,x0=split?side*W/2:0,w=split?W/2:W;
      return{x:x0+Math.random()*w,y:Math.random()*H,side};
    });
  }

  // Rainbow takes its color from a table of whole degrees: building a color string for every particle costs about four times more
  const HUES=Array.from({length:360},(_,h)=>`hsla(${h},80%,65%,.5)`);
  function colorFor(p,x0=0,w=W){ // x0 and w: the part of the canvas the particle lives in (in Compare, its half)
    if(COL==='mint')return'rgba(122,255,200,.5)';
    if(COL==='ember')return'rgba(255,150,80,.5)';
    if(COL==='ice')return'rgba(120,190,255,.5)';
    return HUES[Math.floor(((p.x-x0)/w*120+t*20)%360)];
  }

  // One frame: dim the canvas nf times, then move every particle one step along the field and draw that step. s is how many
  // 60 Hz frames it stands for; k is s, or a third of it in slow motion, and shrinks the step and the field's time but not the dim.
  // Compare: each half draws only inside itself; the first half's particles take a random direction every step (the common
  // mistake), the second half's follow the field. A random walk spreads further in one long step than in two short ones, so the
  // first half's steps all have one length: the frame's time (a third of it in slow motion) adds up in ra, and each whole 60th
  // of a second is one step. It then scribbles as wide at any frame rate. See inside draws the arrows after the step.
  function frame(s,nf){
    const k=s*(slowTog.checked?1/3:1);
    ctx.fillStyle=`rgba(5,6,10,${TRAIL})`;
    for(let i=0;i<nf;i++)ctx.fillRect(0,0,W,H);
    if(mode==='compare'){
      ra+=k;const half=W/2,n=Math.floor(ra+1e-9);ra-=n; // the 1e-9: a sum that should be whole but rounds just under it
      for(const side of [0,1]){
        ctx.save();ctx.beginPath();ctx.rect(side*half,0,half,H);ctx.clip();
        for(const p of parts)if(p.side===side){
          if(side)move(p,angleAt(p.x,p.y,t),k,half,half);
          else for(let i=0;i<n;i++)move(p,Math.random()*Math.PI*2,1,0,half);
        }
        ctx.restore();
      }
      ctx.fillStyle='#2a2b33';ctx.fillRect(half-1,0,2,H);
    }else for(const p of parts)move(p,angleAt(p.x,p.y,t),k,0,W);
    t+=0.01*k;
    if(mode==='inside')drawField();
  }
  // One step of one particle in direction a, drawn; one that leaves its part of the canvas (x0 to x0 + w) starts again somewhere in it
  function move(p,a,k,x0,w){
    const nx=p.x+Math.cos(a)*SPD*k,ny=p.y+Math.sin(a)*SPD*k;
    ctx.strokeStyle=colorFor(p,x0,w);ctx.lineWidth=1;
    ctx.beginPath();ctx.moveTo(p.x,p.y);ctx.lineTo(nx,ny);ctx.stroke();
    p.x=nx;p.y=ny;
    if(p.x<x0||p.x>x0+w||p.y<0||p.y>H){p.x=x0+Math.random()*w;p.y=Math.random()*H;}
  }
  // See inside: the current at the middle of every grid square, as a small arrow pointing where the field points there now (it is
  // longer at a higher Speed), on its own canvas over the picture
  function drawField(){
    if(field.width!==W||field.height!==H){field.width=W;field.height=H;}
    fctx.clearRect(0,0,W,H);
    fctx.strokeStyle='rgba(244,244,242,.8)';fctx.lineWidth=1.5;fctx.lineCap='round';
    const len=8+5*SPD;
    fctx.beginPath();
    for(let y=GRID/2;y<H;y+=GRID)for(let x=GRID/2;x<W;x+=GRID){
      const a=angleAt(x,y,t),dx=Math.cos(a)*len/2,dy=Math.sin(a)*len/2;
      fctx.moveTo(x-dx,y-dy);fctx.lineTo(x+dx,y+dy);
      fctx.lineTo(x+dx-Math.cos(a-.6)*5,y+dy-Math.sin(a-.6)*5);
      fctx.moveTo(x+dx,y+dy);fctx.lineTo(x+dx-Math.cos(a+.6)*5,y+dy-Math.sin(a+.6)*5);
    }
    fctx.stroke();
  }
  // A settled picture: 40 frames at once, each a 60 Hz frame's worth, so it is the same picture on every screen (the random
  // half's count starts again for it). The canvas is covered completely first, because a see-through dim leaves a faint ghost of
  // whatever was there before
  function prerender(){
    ctx.fillStyle='#05060a';ctx.fillRect(0,0,W,H);
    ra=0;for(let i=0;i<40;i++)frame(1,1);
    unseen=false;
  }

  // loop() keeps one frame requested in raf. A drawn frame stands for the time since the last drawn one (s, at most 50 ms) and dims once per
  // whole 60th, fa carrying the rest; with no dim due nothing is drawn and the time carries on, which also caps drawing near 60 a second.
  function loop(ts){
    raf=requestAnimationFrame(loop);
    if(lastT===null){lastT=ts;return;}
    const s=Math.min(ts-lastT,50)/FRAME,w=Math.max(1,Math.round(s));
    const f=fa+(Math.abs(s-w)<.05?w:s),nf=Math.round(f+.05); // within 5% of a whole number counts as it; the .05 keeps a half-way tie off the edge
    if(!nf)return;
    fa=f-nf;lastT=ts;
    frame(s,nf);unseen=false;
  }
  function start(){if(raf)return;lastT=null;fa=0;raf=requestAnimationFrame(loop);}

  // Registered at the top level, before the shared script (deferred) can run: under reduced motion it pauses the
  // loop on arrival, which this listener must catch. The picture on screen stays as it is while paused, unless a
  // setting changed just before and no frame has drawn it yet.
  document.addEventListener('hb:pause',e=>{
    paused=e.detail.paused;
    if(paused){cancelAnimationFrame(raf);raf=null;if(unseen)prerender();}
    else start();
  });
  // A tab that comes back after being hidden has no earlier frame to measure from, so its first frame adds no step
  document.addEventListener('visibilitychange',()=>{lastT=null;fa=0;});
  // The mode switch draws the mode at once. Compare keeps Normal's picture, particles and time, splits the particles into its two
  // halves and draws a settled picture of them; leaving Compare puts Normal's back, its time too, so the arrows still match the trails
  // (or draws it again after a setting or size change). See inside draws the arrows over the picture: every frame while it plays,
  // at once while paused.
  document.addEventListener('hb:mode',e=>{
    const was=mode;mode=e.detail.mode;
    if(mode==='compare'&&was!=='compare'){keep.width=W;keep.height=H;kctx.drawImage(cvs,0,0);kept=parts;keptT=t;init();prerender();}
    else if(was==='compare'&&mode!=='compare'){
      if(kept&&keep.width===W&&keep.height===H){ctx.drawImage(keep,0,0);parts=kept;t=keptT;}else{init();prerender();}
      kept=null;
    }
    if(mode==='inside')drawField();else fctx.clearRect(0,0,field.width,field.height);
  });

  // Setting the canvas size wipes it, so a real change of the stage's size starts the particles again with a settled
  // picture at once, playing or paused. A resize that leaves the stage as it was (a phone's address bar sliding in or out) does nothing.
  function resize(){
    const w=stage.clientWidth,h=stage.clientHeight;
    if(w===W&&h===H)return;
    W=cvs.width=w;H=cvs.height=h;
    kept=null;
    init();prerender();
  }

  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);
    }));
  }
  // Playing, the next frames show a changed setting. Paused, the trails need steps to show it, so a fresh settled picture
  // is drawn; if Pause comes before any frame has, the picture is drawn then. Speed changes no picture in Normal: it keeps the one on screen.
  function changed(){kept=null;if(paused)prerender();else unseen=true;} // a kept Normal picture would show the old setting
  choices('scale-seg',d=>{SCALE=+d.px;changed();});
  choices('trail-seg',d=>{TRAIL=+d.fade;changed();});
  // See inside's arrows and Compare's halves follow Speed at once, paused too (Compare's kept Normal picture stays good: Speed changes none)
  choices('speed-seg',d=>{SPD=+d.spd;if(mode==='inside'&&paused)drawField();else if(mode==='compare'&&paused)prerender();});
  choices('count-seg',d=>{COUNT=+d.n;init();changed();});
  choices('color-seg',d=>{COL=d.col;changed();});

  resize();
  window.addEventListener('resize',resize);
  start();
  phone.addEventListener('change',()=>{init();changed();}); // a window that crosses the phone size changes how many particles it shows
</script>
</body>
</html>