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: 2D Physics: Show me drops land on each other, the home preview pile falls and fades in one cycle, and a press picks the nearest ball within a 44px reach
matin759bb4a82a54
diff --git a/animations/06-3d-advanced/physics-2d/README.md b/animations/06-3d-advanced/physics-2d/README.mdindex 5e9987d8..bdd9ad61 100644--- a/animations/06-3d-advanced/physics-2d/README.md+++ b/animations/06-3d-advanced/physics-2d/README.md@@ -54,7 +54,7 @@ Then every ball moves by its speed (never more than about one radius a step, so**Sleeping.** When no ball has moved faster than about 0.14 px a step for 45 steps (three quarters of a second), every speed is set to zero and the loop stops drawing. A new ball, a throw, a removed ball or a new gravity wakes it again.-**Throwing.** Pressing a ball holds it: it follows the pointer, nothing pushes it, and it pushes the others. Pointer moves give the pointer's speed in pixels per 1/60 s, smoothed over the last few moves; letting go throws the ball with that speed if the pointer was still moving in the last 80 ms.+**Throwing.** Pressing picks up the nearest ball in reach, which is its radius plus 8px and never less than a 44px circle, so a small ball is still easy to catch with a finger. A held ball follows the pointer, nothing pushes it, and it pushes the others. Pointer moves give the pointer's speed in pixels per 1/60 s, smoothed over the last few moves; letting go throws the ball with that speed if the pointer was still moving in the last 80 ms.**Reduced motion.** Nothing falls on screen. The steps of a drop or throw run at once, out of sight, until everything is still, and the new ball fades in where it came to rest:diff --git a/animations/06-3d-advanced/physics-2d/index.html b/animations/06-3d-advanced/physics-2d/index.htmlindex f6580e2b..d8051c49 100644--- a/animations/06-3d-advanced/physics-2d/index.html+++ b/animations/06-3d-advanced/physics-2d/index.html@@ -151,8 +151,7 @@ const FRAME=1000/60,FADE=300,RING=450; // one physics step is 1/60 s; a fade andconst WALL={vx:0,vy:0,im:0}; // the walls and floor never moveconst clamp=(v,a,b)=>Math.max(a,Math.min(b,v));let W=0,H=0,R0=20,balls=[],rings=[],made=0,held=null,raf=null,lastT=null,behind=0,clock=0,awake=false,calm=0,runTimers=[];-let GRAV=1,E=.5,MIX=false,SHOW=false;-const target={x:0,y:0},grab={x:0,y:0},pv={x:0,y:0},last={x:0,y:0,t:0};+let GRAV=1,E=.5,MIX=false,SHOW=false;const target={x:0,y:0},grab={x:0,y:0},pv={x:0,y:0},last={x:0,y:0,t:0};// One physics step of 1/60 s. Gravity, then the contacts: touching pairs and the four walls. Each contact pushes only apart,// and one that closes faster than 1 px a step bounces back with E of its speed (slower ones just rest). Eight passes over all@@ -204,8 +203,7 @@ function draw(){ctx.globalAlpha=b.al;ctx.fillStyle=b.c;ctx.beginPath();ctx.arc(b.x,b.y,b.r,0,Math.PI*2);ctx.fill();ctx.globalAlpha=b.al*.55;ctx.fillStyle=MARK;ctx.beginPath(); // a spot on the ball turns as it rollsctx.arc(b.x+Math.cos(b.a)*b.r*.55,b.y+Math.sin(b.a)*b.r*.55,b.r*.16,0,Math.PI*2);ctx.fill();- const s=Math.hypot(b.vx,b.vy);- if(!SHOW||s<.3)continue;+ const s=Math.hypot(b.vx,b.vy);if(!SHOW||s<.3)continue;const L=Math.min(s*6,b.r*3),ux=b.vx/s,uy=b.vy/s,ex=b.x+ux*L,ey=b.y+uy*L;ctx.globalAlpha=b.al;ctx.beginPath();ctx.moveTo(b.x,b.y);ctx.lineTo(ex,ey);ctx.stroke();ctx.beginPath();ctx.moveTo(ex+ux*6,ey+uy*6);ctx.lineTo(ex-uy*4,ey+ux*4);ctx.lineTo(ex+uy*4,ey-ux*4);ctx.fill();@@ -217,8 +215,7 @@ function fade(ms){let gone=false;for(const b of balls)if(b.al!==b.to){b.al=b.to>b.al?Math.min(b.to,b.al+ms/FADE):Math.max(b.to,b.al-ms/FADE);if(!b.al&&!b.to)gone=true;}rings=rings.filter(r=>clock-r.t<RING);- if(!gone)return;- balls=balls.filter(b=>b.al||b.to);+ if(!gone)return;balls=balls.filter(b=>b.al||b.to);if(held&&!balls.includes(held))held=null;if(reduce.matches)settle();else wake(); // the balls that rested on it fall into the gap}@@ -251,12 +248,14 @@ function drop(x,y){showHint();wake();}-// Pointer Events cover mouse, touch and pen. Pressing a ball picks it up; pressing anywhere else drops a new one. While a ball is+// Pointer Events cover mouse, touch and pen. Pressing a ball picks up the nearest one in reach (its radius plus 8px, and at least+// a 44px circle); pressing anywhere else drops a new one. While a ball is// held, the pointer's speed is followed (in px per 1/60 s), and letting go throws the ball with it if the pointer was still moving.const local=e=>{const r=cvs.getBoundingClientRect();return {x:e.clientX-r.left,y:e.clientY-r.top};};cvs.addEventListener('pointerdown',e=>{if(!e.isPrimary||e.button!==0)return;- const p=local(e),b=balls.filter(o=>o.to>0).reverse().find(o=>(o.x-p.x)**2+(o.y-p.y)**2<(o.r+8)**2);+ const p=local(e);let b=null,best=Infinity;+ for(const o of balls){const d=Math.hypot(o.x-p.x,o.y-p.y);if(o.to>0&&d<=Math.max(o.r+8,22)&&d-o.r<best){best=d-o.r;b=o;}}if(!b){drop(p.x,p.y);return;}held=b;grab.x=b.x-p.x;grab.y=b.y-p.y;target.x=b.x;target.y=b.y;pv.x=pv.y=0;Object.assign(last,p,{t:e.timeStamp});try{cvs.setPointerCapture(e.pointerId);}catch(_){}@@ -279,14 +278,15 @@ const release=e=>{// The keyboard drops a ball at a random spot near the topcvs.addEventListener('keydown',e=>{if((e.key==='Enter'||e.key===' ')&&!e.repeat){e.preventDefault();drop(W*(.2+Math.random()*.6),H*.15);}});-// Show me: five clicks' worth, 0.3 s apart, then the balls rest and fade out 1.7 s after the last one, so the box is empty again.+// Show me: five clicks' worth, 0.3 s apart and a ball's width or less from the middle, so each new ball lands on the ones before+// and they pile up; they fade out 1.7 s after the last one, so the box is empty again.// Slow motion stretches the waits three times. Every timer of the run goes through later(); stopRun() cancels the rest of it.function later(fn,ms){const id=setTimeout(()=>{runTimers=runTimers.filter(t=>t!==id);fn();},ms*(slowTog.checked?3:1));runTimers.push(id);}function stopRun(){runTimers.forEach(clearTimeout);runTimers=[];}document.getElementById('btn-demo').addEventListener('click',e=>{if(!e.isTrusted&&balls.some(b=>b.to>0))return; // the press on arrival leaves alone a box the visitor has already filledstopRun();balls=[];rings=[];held=null;awake=false;showHint();draw();- [[.3,.18],[.62,.12],[.46,.22],[.72,.16],[.4,.1]].forEach(([x,y],i)=>later(()=>drop(W*x,H*y),300*i));+ [[0,.18],[1.1,.12],[-1.2,.22],[.5,.16],[-.4,.1]].forEach(([x,y],i)=>later(()=>drop(W/2+R0*x,H*y),300*i));later(()=>{balls.forEach(b=>{b.to=0;});showHint();kick();},2900);});document.getElementById('btn-reset').addEventListener('click',()=>{stopRun();held=null;balls.forEach(b=>{b.to=0;});showHint();kick();});diff --git a/index.html b/index.htmlindex 29626148..a483ff48 100644--- a/index.html+++ b/index.html@@ -804,9 +804,14 @@ button,input{font:inherit;color:inherit}@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}}.pv-phys2d{background:#0b0b0d;overflow:hidden}.pv-phys2d::after{content:"";position:absolute;left:0;right:0;bottom:0;height:3%;background:#1c2029}-.pv-phys2d i{position:absolute;left:calc(var(--x) - 5.5%);bottom:calc(3% + var(--b));width:11%;aspect-ratio:1;border-radius:50%;background:var(--c);animation:d-phfall 5s infinite backwards;animation-delay:calc(var(--i)*.25s)}+.pv-phys2d i{position:absolute;left:calc(var(--x) - 5.5%);bottom:calc(3% + var(--b));width:11%;aspect-ratio:1;border-radius:50%;background:var(--c);animation:var(--k) 5s infinite,d-phfade 5s infinite}.pv-phys2d i::after{content:"";position:absolute;left:58%;top:22%;width:18%;height:18%;border-radius:50%;background:rgba(255,255,255,.55)}-@keyframes d-phfall{0%{transform:translateY(-500%);opacity:0;animation-timing-function:cubic-bezier(.5,0,1,.6)}1%{opacity:1}12%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}17%{transform:translateY(-55%);animation-timing-function:cubic-bezier(.5,0,1,.6)}22%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}25%{transform:translateY(-14%);animation-timing-function:cubic-bezier(.5,0,1,.6)}28%,84%{transform:translateY(0);opacity:1}92%,100%{transform:translateY(0);opacity:0}}+/* One shared 5 s cycle: each ball falls at its own moment (a row only once the row below has settled), and the pile fades as one */+@keyframes d-ph0{0%{transform:translateY(-620%);animation-timing-function:cubic-bezier(.5,0,1,.6)}12%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}17%{transform:translateY(-55%);animation-timing-function:cubic-bezier(.5,0,1,.6)}22%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}25%{transform:translateY(-14%);animation-timing-function:cubic-bezier(.5,0,1,.6)}28%,100%{transform:translateY(0)}}+@keyframes d-ph1{0%,4%{transform:translateY(-620%);animation-timing-function:cubic-bezier(.5,0,1,.6)}16%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}21%{transform:translateY(-55%);animation-timing-function:cubic-bezier(.5,0,1,.6)}26%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}29%{transform:translateY(-14%);animation-timing-function:cubic-bezier(.5,0,1,.6)}32%,100%{transform:translateY(0)}}+@keyframes d-ph2{0%,22%{transform:translateY(-620%);animation-timing-function:cubic-bezier(.5,0,1,.6)}34%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}37%{transform:translateY(-22%);animation-timing-function:cubic-bezier(.5,0,1,.6)}40%,100%{transform:translateY(0)}}+@keyframes d-ph3{0%,32%{transform:translateY(-620%);animation-timing-function:cubic-bezier(.5,0,1,.6)}44%{transform:translateY(0);animation-timing-function:cubic-bezier(0,.4,.5,1)}47%{transform:translateY(-22%);animation-timing-function:cubic-bezier(.5,0,1,.6)}50%,100%{transform:translateY(0)}}+@keyframes d-phfade{0%,84%{opacity:1}92%,100%{opacity:0}}/* ── bespoke: 07 Ambient & Background ── */.pv-grain2{background:radial-gradient(circle at 50% 40%,#1a1710,#08080a);overflow:hidden}@@ -1506,7 +1511,7 @@ function pvMarkup(k){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 'phys2d': return [[50,0,'c5'],[38.5,0,'c1'],[61.5,0,'c3'],[44.25,15,'c7'],[55.75,15,'c2'],[50,30,'c6']].map(function(b,i){return '<i class="anim" style="--x:'+b[0]+'%;--b:'+b[1]+'%;--i:'+i+';--c:var(--'+b[2]+')"></i>';}).join('');+ case 'phys2d': return [[50,0,'c5',0],[38.5,0,'c1',1],[61.5,0,'c3',1],[44.25,15,'c7',2],[55.75,15,'c2',2],[50,30,'c6',3]].map(function(b){return '<i class="anim" style="--x:'+b[0]+'%;--b:'+b[1]+'%;--c:var(--'+b[2]+');--k:d-ph'+b[3]+'"></i>';}).join('');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>';