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: Noise-Based Motion shows the noise as a gray map behind the leaning dots, or the plain circle with push arrows (See inside) and plain random beside smooth noise (Compare)
matin0923f0af223b
diff --git a/animations/06-3d-advanced/noise-based-motion/index.html b/animations/06-3d-advanced/noise-based-motion/index.htmlindex d051f525..8c1ced04 100644--- a/animations/06-3d-advanced/noise-based-motion/index.html+++ b/animations/06-3d-advanced/noise-based-motion/index.html@@ -23,8 +23,17 @@<style>:root{--ui-accent:#3fd6c4}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}- .stage{background:#0b0b0d}+ .stage{position:relative;overflow:hidden;background:#0b0b0d}canvas{display:block;width:100%;height:100%}+ /* See inside and Compare: plain words over the picture */+ .lbl{display:none;position:absolute;padding:4px 9px;border-radius:999px;background:rgba(11,11,13,.9);color:#f4f4f2;font:600 13px/1.2 var(--hb-font);white-space:nowrap;pointer-events:none}+ .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=10"><script src="../../../assets/js/demo-page.js?v=10" defer></script>@@ -47,13 +56,26 @@<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" id="stage"><canvas id="cvs" role="img" aria-label="Small dots swaying on a dark background, or a single blob with a rippling edge"></canvas>+ <p class="lbl fl what" aria-hidden="true" data-hb-caption>Gray: the noise, a smooth pattern</p>+ <p class="lbl fl how" aria-hidden="true" data-hb-caption>Each dot leans by the gray under it</p>+ <p class="lbl side first" aria-hidden="true" data-hb-caption>Plain random</p>+ <p class="lbl side second" aria-hidden="true" data-hb-caption>Smooth noise</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 gray is the noise: a value that changes gradually from place to place. Each dot leans by the value under it, so neighbors lean alike.</p>+ <p data-hb-for="compare" hidden>Plain random hands each dot a fresh random number, so neighbors point every which way, like static. Smooth noise changes gradually from place to place, so neighbors lean alike.</p>+ </div></section><section class="hb-step hb-try" aria-labelledby="hb-try-title">@@ -193,6 +215,18 @@ const cvs=document.getElementById('cvs');const ctx=cvs.getContext('2d');const stage=document.getElementById('stage');const slowTog=document.getElementById('slow-tog');let W,H,paused=false,raf=null,last=null,t=0;let MODE='grid',SCALE=.008,SPD=.5,AMP=12,SPACE=48,COLOR='#58a6ff';+// See inside and Compare. VIEW is the mode the visitor pressed. In Compare the first half takes a fixed random number for each+// dot (or edge point) in place of the noise, and a new roll of them comes every 100 ms of elapsed time (a third as often in slow+// motion): ra adds up the time, roll counts the rolls. A fixed hash makes a still the same every time. RANGE is the spread+// the noise mostly has, so both halves push about as far.+let VIEW='normal',roll=0,ra=0;+const phone=matchMedia('(max-width:600px),(max-height:500px)');+const TOP=44,REROLL=100,RANGE=.7;+function rnd(a,b){+ let h=Math.imul(a+1,374761393)^Math.imul(b+1,668265263)^Math.imul(roll+1,1274126177);+ h=Math.imul(h^(h>>>13),1103515245);h^=h>>>16;+ return ((h>>>0)/2147483648-1)*RANGE;+}const VERTS=96; // 96 points keep the edge smooth even where the ripple is sharpest// The blob reads the noise along a circle of radius RING x SCALE (the inner ring RING_IN x SCALE). A tiny circle sees almost// one value, so the whole edge only swells and shrinks; this one is wide enough for about two lobes at the default size.@@ -206,30 +240,40 @@ function resize(){}// The dots sit SPACE pixels apart, so a narrow phone stage draws fewer of them than a wide one.-function drawGrid(){- const step=SPACE;+// ox, oy, w, h: the part of the canvas it fills (all of it in Normal); rand: a fixed random number in place of the noise.+// In a view the dots are a little larger and their lines bolder, so a lean reads in a still; See inside also rings each home.+// Compare centers the grid in its half.+function drawGrid(ox=0,oy=0,w=W,h=H,rand=false){+ const step=SPACE,view=VIEW!=='normal';+ const ex=VIEW==='compare'?(w%step)/2:0,ey=VIEW==='compare'?(h%step)/2:0;const r=parseInt(COLOR.slice(1,3),16),g=parseInt(COLOR.slice(3,5),16),b=parseInt(COLOR.slice(5,7),16);- for(let x=step/2;x<W;x+=step){- for(let y=step/2;y<H;y+=step){- const n=simplex2(x*SCALE,y*SCALE+t);+ for(let x=ex+step/2,i=0;x<w;x+=step,i++){+ for(let y=ey+step/2,j=0;y<h;y+=step,j++){+ const n=rand?rnd(i,j):simplex2(x*SCALE,y*SCALE+t);const dx=Math.cos(n*Math.PI*2)*AMP;const dy=Math.sin(n*Math.PI*2)*AMP;const op=.4+Math.abs(n)*.5;ctx.fillStyle=`rgba(${r},${g},${b},${op.toFixed(2)})`;- ctx.beginPath();ctx.arc(x+dx,y+dy,1.5,0,Math.PI*2);ctx.fill();- ctx.strokeStyle=`rgba(${r},${g},${b},${(op*.4).toFixed(2)})`;- ctx.lineWidth=.5;ctx.beginPath();ctx.moveTo(x,y);ctx.lineTo(x+dx,y+dy);ctx.stroke();+ ctx.beginPath();ctx.arc(ox+x+dx,oy+y+dy,view?2.2:1.5,0,Math.PI*2);ctx.fill();+ ctx.strokeStyle=`rgba(${r},${g},${b},${(op*(view?.85:.4)).toFixed(2)})`;+ ctx.lineWidth=view?1.25:.5;ctx.beginPath();ctx.moveTo(ox+x,oy+y);ctx.lineTo(ox+x+dx,oy+y+dy);ctx.stroke();+ if(VIEW==='inside'){+ ctx.strokeStyle='rgba(244,244,242,.35)';ctx.lineWidth=1;+ ctx.beginPath();ctx.arc(ox+x,oy+y,3.5,0,Math.PI*2);ctx.stroke();+ }}}}-function drawBlob(){- const cx=W/2,cy=H/2;const R=Math.min(W,H)*.28;+// How far the noise pushes the blob's edge at angle a (before the doubling)+const edgeN=a=>simplex2(Math.cos(a)*SCALE*RING+t,Math.sin(a)*SCALE*RING)*AMP;+function drawBlob(ox=0,oy=0,w=W,h=H,rand=false){+ const cx=ox+w/2,cy=oy+h/2;const R=Math.min(w,h)*.28;const r=parseInt(COLOR.slice(1,3),16),g=parseInt(COLOR.slice(3,5),16),b=parseInt(COLOR.slice(5,7),16);ctx.beginPath();for(let i=0;i<=VERTS;i++){const a=(i/VERTS)*Math.PI*2;- const n=simplex2(Math.cos(a)*SCALE*RING+t,Math.sin(a)*SCALE*RING)*AMP;+ const n=rand?rnd(i%VERTS,0)*AMP:edgeN(a);const r2=R+n*2;const px=cx+Math.cos(a)*r2,py=cy+Math.sin(a)*r2;i===0?ctx.moveTo(px,py):ctx.lineTo(px,py);@@ -241,7 +285,7 @@ function drawBlob(){ctx.beginPath();for(let i=0;i<=VERTS;i++){const a=(i/VERTS)*Math.PI*2;- const n=simplex2(Math.cos(a)*SCALE*RING_IN+t*.7,Math.sin(a)*SCALE*RING_IN)*AMP*.5;+ const n=(rand?rnd(i%VERTS,1):simplex2(Math.cos(a)*SCALE*RING_IN+t*.7,Math.sin(a)*SCALE*RING_IN))*AMP*.5;const r2=R*.5+n*1.5;const px=cx+Math.cos(a)*r2,py=cy+Math.sin(a)*r2;i===0?ctx.moveTo(px,py):ctx.lineTo(px,py);@@ -250,7 +294,54 @@ function drawBlob(){ctx.strokeStyle=`rgba(${r},${g},${b},.3)`;ctx.lineWidth=1;ctx.stroke();}-function frame(){ctx.clearRect(0,0,W,H);if(MODE==='grid')drawGrid();else drawBlob();}+// See inside: the noise as a gray map, one value per cell, worked out with the dots' own formula and clock and drawn smooth+const mapC=document.createElement('canvas'),mctx=mapC.getContext('2d');+let mapImg=null,mapPx=null;+function drawMap(){+ const cell=phone.matches?12:8,cw=Math.ceil(W/cell),ch=Math.ceil(H/cell);+ if(!mapImg||mapC.width!==cw||mapC.height!==ch){mapC.width=cw;mapC.height=ch;mapImg=mctx.createImageData(cw,ch);mapPx=new Uint32Array(mapImg.data.buffer);}+ for(let j=0;j<ch;j++)for(let i=0;i<cw;i++){+ const n=simplex2((i+.5)*cell*SCALE,(j+.5)*cell*SCALE+t);+ const v=Math.max(0,Math.min(255,Math.round(128+n*180)));+ mapPx[j*cw+i]=0xff000000|v<<16|v<<8|v;+ }+ mctx.putImageData(mapImg,0,0);+ ctx.globalAlpha=.34;ctx.drawImage(mapC,0,0,cw*cell,ch*cell);ctx.globalAlpha=1;+}+// See inside, Blob: the plain circle, and sixteen arrows from it to the edge, drawn at the angles the edge is read at+function drawPush(){+ const cx=W/2,cy=H/2,R=Math.min(W,H)*.28;+ ctx.setLineDash([5,5]);ctx.strokeStyle='rgba(244,244,242,.75)';ctx.lineWidth=1.5;+ ctx.beginPath();ctx.arc(cx,cy,R,0,Math.PI*2);ctx.stroke();ctx.setLineDash([]);+ ctx.strokeStyle='#f4f4f2';ctx.fillStyle='#f4f4f2';ctx.lineWidth=2;ctx.lineCap='round';+ for(let k=0;k<16;k++){+ const a=k/16*Math.PI*2,c=Math.cos(a),s=Math.sin(a),d=edgeN(a)*2,len=Math.abs(d);+ const x0=cx+c*R,y0=cy+s*R,x1=cx+c*(R+d),y1=cy+s*(R+d);+ if(len<3){ctx.beginPath();ctx.arc(x0,y0,2,0,Math.PI*2);ctx.fill();continue;}+ const hd=Math.min(6,len*.6),u=d>0?1:-1;+ ctx.beginPath();ctx.moveTo(x0,y0);ctx.lineTo(x1,y1);+ for(const o of [-.6,.6]){ctx.moveTo(x1,y1);ctx.lineTo(x1-u*(c*Math.cos(o)-s*Math.sin(o))*hd,y1-u*(s*Math.cos(o)+c*Math.sin(o))*hd);}+ ctx.stroke();+ }+ ctx.lineCap='butt';+}+// Compare: one canvas, each half clipped to its own side and starting below its name; the first half's numbers are random+function drawSplit(){+ const hw=W/2;+ for(let side=0;side<2;side++){+ ctx.save();ctx.beginPath();ctx.rect(side*hw,0,hw,H);ctx.clip();+ if(MODE==='grid')drawGrid(side*hw,TOP,hw,H-TOP,!side);else drawBlob(side*hw,TOP,hw,H-TOP,!side);+ ctx.restore();+ }+ ctx.fillStyle='rgba(244,244,242,.3)';ctx.fillRect(hw-1,0,2,H);+}+function frame(){+ ctx.clearRect(0,0,W,H);+ if(VIEW==='compare')drawSplit();+ else if(VIEW==='inside'){+ if(MODE==='grid'){drawMap();drawGrid();}else{drawBlob();drawPush();}+ }else if(MODE==='grid')drawGrid();else drawBlob();+}// One step is 1/60 s: the noise moves on by SPD x 0.01 in that time, whatever the screen's refresh rate.const FRAME=1000/60;@@ -262,6 +353,7 @@ function loop(ts){if(last===null){last=ts;return;} // the first frame after a start only takes the timeconst dt=ts-last;if(dt<16)return;last=ts;t+=SPD*.01*(Math.min(dt,50)/FRAME)/(slowTog.checked?3:1);+ if(VIEW==='compare'){ra+=Math.min(dt,50)/(slowTog.checked?3:1);if(ra>=REROLL){roll+=Math.floor(ra/REROLL);ra%=REROLL;}}frame();}function start(){if(raf)return;last=null;raf=requestAnimationFrame(loop);}@@ -278,6 +370,30 @@ document.addEventListener('hb:pause',e=>{else start();});+// The words each view and shape use (Field of dots is the markup's own): the two captions, the two notes, the picture's name+const hbFor=m=>document.querySelector('[data-hb-for="'+m+'"]');+const WORDS={+ grid:{what:'Gray: the noise, a smooth pattern',how:'Each dot leans by the gray under it',+ inside:hbFor('inside').textContent,compare:hbFor('compare').textContent,+ ain:'Dots swaying over a gray map of the noise: each dot leans by the value under it',+ acmp:'Two fields of dots: one moved by plain random numbers that keep changing, one by smooth noise'},+ blob:{what:'Dashed: a plain circle',how:'Arrows: noise pushes the edge out or in',+ inside:'Inside, the dashed line is a plain circle. The noise, read around it, pushes each part of the edge out or in by the arrow’s length; neighbors push alike, so the edge forms smooth waves.',+ compare:'Plain random pushes each part of the edge by its own random number, so the edge is jagged. Smooth noise changes gradually around the edge, so it forms smooth waves.',+ ain:'A blob whose edge is pushed out or in by the noise, with a dashed plain circle and arrows showing each push',+ acmp:'Two blobs: one with its edge pushed by plain random numbers, jagged, one by smooth noise, rippling'}+};+const NORMAL_NAME=cvs.getAttribute('aria-label');+const lbl=c=>document.querySelector('.'+c);+function put(el,text){if(el.textContent!==text)el.textContent=text;}+function looks(){+ const w=WORDS[MODE];+ put(lbl('what'),w.what);put(lbl('how'),w.how);put(hbFor('inside'),w.inside);put(hbFor('compare'),w.compare);+ cvs.setAttribute('aria-label',VIEW==='inside'?w.ain:VIEW==='compare'?w.acmp:NORMAL_NAME);+}+// The mode switch draws the mode at once. Normal keeps its clock, which every view uses+document.addEventListener('hb:mode',e=>{VIEW=e.detail.mode;ra=0;looks();frame();});+resize();frame();start();window.addEventListener('resize',()=>{if(stage.clientWidth===W&&stage.clientHeight===H)return;resize();redraw();});@@ -290,7 +406,7 @@ function choices(id,pick){}const spaceSetting=document.getElementById('space-setting');// The spacing only matters for the field of dots-choices('shape-seg',d=>{MODE=d.mode;spaceSetting.hidden=MODE!=='grid';});+choices('shape-seg',d=>{MODE=d.mode;spaceSetting.hidden=MODE!=='grid';looks();});choices('size-seg',d=>{SCALE=+d.scale;});choices('speed-seg',d=>{SPD=+d.spd;});choices('wobble-seg',d=>{AMP=+d.amp;});