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: fade the home page's trail previews the same way at every screen rate
matina1126c2f2d04
diff --git a/index.html b/index.htmlindex 6f907303..5a899e06 100644--- a/index.html+++ b/index.html@@ -1251,15 +1251,17 @@ CATS.forEach(cat=>{const reduce=matchMedia('(prefers-reduced-motion:reduce)').matches;// Previews move by elapsed time in 60 Hz frames (steps), so they run at the same speed on any screen. The first frame after a start adds none; a gap over 50 ms counts as 50.+// Trails fade once per 60 Hz frame of elapsed time at the fixed 60 Hz opacity (fa counts the fades owed): a smaller opacity on faster screens would round differently in an 8-bit canvas. Starfield and flow draw nothing on a frame with no step.const FRAME=1000/60;function starfield(pv){const c=document.createElement('canvas');pv.appendChild(c);const ctx=c.getContext('2d');- let w,h,stars,raf=null,last=null;+ let w,h,stars,raf=null,last=null,fa=0;function size(){const r=pv.getBoundingClientRect();w=c.width=r.width*devicePixelRatio;h=c.height=r.height*devicePixelRatio;stars=Array.from({length:90},()=>({x:(Math.random()-.5)*w,y:(Math.random()-.5)*h,z:Math.random()*w}));draw(false);}function draw(advance,steps){- ctx.fillStyle=advance?'rgba(4,5,12,'+(1-Math.pow(1-.35,steps))+')':'#04050c';ctx.fillRect(0,0,w,h);+ if(advance){if(!steps)return;fa+=steps;const nf=Math.round(fa);fa-=nf;ctx.fillStyle='rgba(4,5,12,.35)';for(let i=0;i<nf;i++)ctx.fillRect(0,0,w,h);}+ else{ctx.fillStyle='#04050c';ctx.fillRect(0,0,w,h);}ctx.save();ctx.translate(w/2,h/2);for(const s of stars){if(advance){s.z-=w*.004*steps;if(s.z<1){s.z=w;s.x=(Math.random()-.5)*w;s.y=(Math.random()-.5)*h;}}const k=128/s.z,x=s.x*k,y=s.y*k,size=(1-s.z/w)*2.4*devicePixelRatio;@@ -1268,7 +1270,7 @@ function starfield(pv){}function frame(ts){const steps=last==null?0:Math.min(ts-last,50)/FRAME;last=ts;draw(true,steps);raf=requestAnimationFrame(frame);}size();addEventListener('resize',size);- return {play(){if(!raf&&!reduce){last=null;raf=requestAnimationFrame(frame);}},pause(){if(raf){cancelAnimationFrame(raf);raf=null;}}};+ return {play(){if(!raf&&!reduce){last=null;fa=0;raf=requestAnimationFrame(frame);}},pause(){if(raf){cancelAnimationFrame(raf);raf=null;}}};}function scramble(pv){const el=pv.querySelector('.txt'),final='SCRAMBLE',chars='ABCDEFGHJKLMNPQRSTUVWXYZ#%$&/<>*';let t=null,locked=0;@@ -1303,11 +1305,12 @@ function particlesFactory(pv,count,connect){}function flowEngine(pv){const c=document.createElement('canvas');pv.appendChild(c);const ctx=c.getContext('2d');- let w,h,ps,raf=null,last=null;const D=devicePixelRatio;+ let w,h,ps,raf=null,last=null,fa=0;const D=devicePixelRatio;function ang(x,y){return (Math.sin(x*0.9+y*0.6)+Math.cos(y*1.1-x*0.5))*Math.PI;}function size(){const r=pv.getBoundingClientRect();w=c.width=r.width*D;h=c.height=r.height*D;ps=Array.from({length:55},()=>({x:Math.random()*w,y:Math.random()*h}));ctx.fillStyle='#05060a';ctx.fillRect(0,0,w,h);}- function draw(steps){ctx.fillStyle='rgba(5,6,10,'+(1-Math.pow(1-.09,steps))+')';ctx.fillRect(0,0,w,h);ctx.fillStyle='rgba(95,216,138,.85)';+ function draw(steps){if(!steps)return;+ fa+=steps;const nf=Math.round(fa);fa-=nf;ctx.fillStyle='rgba(5,6,10,.09)';for(let i=0;i<nf;i++)ctx.fillRect(0,0,w,h);ctx.fillStyle='rgba(95,216,138,.85)';// a step longer than one frame is drawn in pieces of about one frame, so the trails have no gaps at 30 Hzconst n=Math.max(1,Math.round(steps)),s=steps/n;for(const p of ps)for(let i=0;i<n;i++){const a=ang(p.x/(70*D),p.y/(70*D));p.x+=Math.cos(a)*1.2*D*s;p.y+=Math.sin(a)*1.2*D*s;@@ -1315,7 +1318,7 @@ function flowEngine(pv){ctx.fillRect(p.x,p.y,1.5*D,1.5*D);}}function frame(ts){const steps=last==null?0:Math.min(ts-last,50)/FRAME;last=ts;draw(steps);raf=requestAnimationFrame(frame);}size();addEventListener('resize',size);- return {play(){if(!raf&&!reduce){last=null;raf=requestAnimationFrame(frame);}},pause(){if(raf){cancelAnimationFrame(raf);raf=null;}}};+ return {play(){if(!raf&&!reduce){last=null;fa=0;raf=requestAnimationFrame(frame);}},pause(){if(raf){cancelAnimationFrame(raf);raf=null;}}};}const engines={starfield,scramble,counter,particles:pv=>particlesFactory(pv,46,true),gpgpu:pv=>particlesFactory(pv,150,false),flow:flowEngine};