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
fix: keep WebGL's paused picture, recover from a failed build and let Noise's blob ripple
matin7a70c7f98e33
diff --git a/animations/06-3d-advanced/noise-based-motion/README.md b/animations/06-3d-advanced/noise-based-motion/README.mdindex e333e6d2..cd08a246 100644--- a/animations/06-3d-advanced/noise-based-motion/README.md+++ b/animations/06-3d-advanced/noise-based-motion/README.md@@ -42,8 +42,8 @@ The demo sets `step` as a spacing in pixels rather than a number of columns, soctx.beginPath();for (let i = 0; i <= vertices; i++) {const a = (i / vertices) * Math.PI * 2;- const n = simplex2(Math.cos(a) * 12 * SCALE + time,- Math.sin(a) * 12 * SCALE);+ const n = simplex2(Math.cos(a) * 48 * SCALE + time,+ Math.sin(a) * 48 * SCALE);const r = baseRadius + n * amplitude * 2;const x = cx + Math.cos(a) * r;const y = cy + Math.sin(a) * r;@@ -52,6 +52,8 @@ for (let i = 0; i <= vertices; i++) {ctx.closePath();```+The noise is read along a circle of radius `48 * SCALE`. A tiny circle would see almost one value, so the whole edge would only swell and shrink together; this one spans about two bumps of noise at the default size, so the edge ripples.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|diff --git a/animations/06-3d-advanced/noise-based-motion/index.html b/animations/06-3d-advanced/noise-based-motion/index.htmlindex 7a22212d..1a68669d 100644--- a/animations/06-3d-advanced/noise-based-motion/index.html+++ b/animations/06-3d-advanced/noise-based-motion/index.html@@ -192,6 +192,9 @@ const stage=document.getElementById('stage');const slowTog=document.getElementBylet W,H,paused=false,raf=null,last=null,t=0;let MODE='grid',SCALE=.008,SPD=.5,AMP=12,SPACE=48,COLOR='#58a6ff';const VERTS=48; // 48 points already draw a smooth edge+// 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.+const RING=48,RING_IN=32;function resize(){const dpr=Math.min(window.devicePixelRatio||1,2);@@ -224,7 +227,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*12+t,Math.sin(a)*SCALE*12)*AMP;+ const n=simplex2(Math.cos(a)*SCALE*RING+t,Math.sin(a)*SCALE*RING)*AMP;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);@@ -236,7 +239,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*8+t*.7,Math.sin(a)*SCALE*8)*AMP*.5;+ const n=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);diff --git a/animations/06-3d-advanced/webgl-shader-animation/README.md b/animations/06-3d-advanced/webgl-shader-animation/README.mdindex 79de2647..32836e8b 100644--- a/animations/06-3d-advanced/webgl-shader-animation/README.md+++ b/animations/06-3d-advanced/webgl-shader-animation/README.md@@ -35,21 +35,22 @@ function render(ts) {}```-**Plasma** — the simplest pattern; nested sine functions over UV coordinates:+**Plasma** — the simplest pattern; nested sine functions over UV coordinates, and the sum picks a hue (`hsv()` turns a hue, a saturation and a brightness into a color):```glslvoid main() {vec2 uv = gl_FragCoord.xy / uRes * 2.0 - 1.0;+ uv.x *= uRes.x / uRes.y; // keep the rings round on a wide stagefloat v = sin(uv.x * 5.0 + uT)+ sin(uv.y * 5.0 + uT * 0.7)- + sin((uv.x + uv.y) * 5.0 + uT * 0.3)- + sin(sqrt(uv.x*uv.x + uv.y*uv.y) * 6.0);- vec3 col = 0.5 + 0.5 * cos(v * 3.14 + vec3(0, 2.09, 4.19));- gl_FragColor = vec4(col, 1.0);+ + sin((uv.x + uv.y) * 5.0 + uT * 0.5)+ + sin(length(uv) * 6.0); // rings around the middle+ float hue = fract(v * 0.25 + uT * 0.05); // the sum picks the hue; time slides it round the rainbow+ gl_FragColor = vec4(hsv(hue, 0.9, 0.95), 1.0);}```-**Voronoi** — cellular pattern using nearest-neighbor distance in a grid:+**Cells (Voronoi)** — cellular pattern using nearest-neighbor distance in a grid; the point in each cell drifts slowly as time runs on:```glslfloat voronoi(vec2 p) {@@ -57,7 +58,7 @@ float voronoi(vec2 p) {float md = 8.0;for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {vec2 n = vec2(x, y);- vec2 pt = n + rand2(i + n); // random point in each cell+ vec2 pt = n + rand2(i + n + uT * 0.01); // a random point in each cell, moving with timemd = min(md, length(pt - f));}return md;diff --git a/animations/06-3d-advanced/webgl-shader-animation/index.html b/animations/06-3d-advanced/webgl-shader-animation/index.htmlindex a4a628ec..0e5041b3 100644--- a/animations/06-3d-advanced/webgl-shader-animation/index.html+++ b/animations/06-3d-advanced/webgl-shader-animation/index.html@@ -199,7 +199,7 @@ void main(){const stage=document.getElementById('stage');const cvs=document.getElementById('cvs');const msgEl=document.getElementById('gl-msg');const slowTog=document.getElementById('slow-tog');let W,H,gl,prog=null,U=null,raf=null,paused=false,last=null,T=0;-let PRESET=0,SPD=1,MOUSE_UV=[.5,.5],MOUSE_ON=false;+let PRESET=0,SPD=1,MOUSE_UV=[.5,.5],SHOWN_UV=[.5,.5],MOUSE_ON=false;const HUE=0; // every pattern already runs through the whole rainbow, so the shaders keep the hue shift at 0// A failed shader is otherwise invisible: the canvas just stays black.@@ -264,7 +264,7 @@ function resize(){function draw(){gl.useProgram(prog);gl.uniform2f(U.R,W,H);gl.uniform1f(U.T,T);gl.uniform1f(U.H,HUE);- if(MOUSE_ON){gl.uniform2f(U.M,MOUSE_UV[0],MOUSE_UV[1]);gl.uniform1i(U.uMouse,1);}+ if(MOUSE_ON){gl.uniform2f(U.M,SHOWN_UV[0],SHOWN_UV[1]);gl.uniform1i(U.uMouse,1);}else gl.uniform1i(U.uMouse,0);gl.drawArrays(gl.TRIANGLE_STRIP,0,4);}@@ -279,6 +279,7 @@ function render(ts){const dt=ts-last;if(dt<16)return;last=ts;T+=Math.min(dt,100)/1000*SPD/(slowTog.checked?3:1);+ SHOWN_UV=MOUSE_UV;draw();}function start(){if(raf!==null||!prog)return;last=null;raf=requestAnimationFrame(render);}@@ -292,7 +293,8 @@ function setPaused(p){// loop on arrival, which this listener must catch. Play carries on from the current clock.document.addEventListener('hb:pause',e=>setPaused(e.detail.paused));-// The pointer is only recorded here; the pattern takes it when a frame is drawn.+// The pointer is only recorded here. The pattern takes it on the next frame that moves on (render sets SHOWN_UV),+// so a repaint while paused shows a new setting and nothing else.// y is flipped because gl_FragCoord counts from the bottom of the buffer.function aim(e){const r=cvs.getBoundingClientRect();MOUSE_UV=[(e.clientX-r.left)/r.width,1-(e.clientY-r.top)/r.height];}@@ -312,7 +314,7 @@ if(init()){});cvs.addEventListener('webglcontextrestored',()=>{if(!init())return;- clearFail();resize();+ resize();if(!paused)start();});}else{@@ -326,7 +328,7 @@ function choices(id,pick){pick(b.dataset);}));}-choices('pattern-seg',d=>{switchShader(+d.pattern);still();});+choices('pattern-seg',d=>{switchShader(+d.pattern);if(paused)still();else start();});choices('speed-seg',d=>{SPD=+d.spd;});document.getElementById('mouse-tog').addEventListener('change',e=>{MOUSE_ON=e.target.checked;still();});</script>