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: Flocking: paused See inside works its pulls out again after a resize, the notes are written only when their words change, and Compare's worlds start below the half names so the flock never sits under them
matind0728c72e2d4
diff --git a/animations/06-3d-advanced/flocking/index.html b/animations/06-3d-advanced/flocking/index.htmlindex 6a33ad09..a4632391 100644--- a/animations/06-3d-advanced/flocking/index.html+++ b/animations/06-3d-advanced/flocking/index.html@@ -304,29 +304,30 @@ function arrow(x0,y0,dx,dy,col,box){ // a line with a head from (x0,y0) by (dx,dbox[0]=Math.min(box[0],x1);box[1]=Math.min(box[1],y1);box[2]=Math.max(box[2],x1);box[3]=Math.max(box[3],y1);}-// Compare: two worlds, one for each half of the box, each with half the birds so it is as crowded as Normal. Both start from the-// same birds (places as shares of the half, headings and speeds from a fixed seed), fly the same 180 moves and then take the same-// moves from the loop's one clock; the first half's birds follow no rules (LONE). Normal's own birds are not touched meanwhile.+// Compare: two worlds, one for each half of the box below its name (no bird flies under it), each with half the birds so it is as+// crowded as Normal. Both start from the same birds (places as shares of the world, headings and speeds from a fixed seed), fly the+// same 180 moves and then take the same moves from the loop's one clock; the first half's birds follow no rules (LONE).+const halfName=stage.querySelector('.half');function makeHalves(){- const hw=W/2;let a=20261022;+ const hw=W/2,top=Math.min(halfName.offsetTop+halfName.offsetHeight+8,H/3),h=H-top;let a=20261022;const rnd=()=>{a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};const start=Array.from({length:Math.round(count()/2)},()=>[rnd(),rnd(),rnd()*Math.PI*2,.6+rnd()*.4]);- halves=[true,false].map(lone=>({W:hw,H,lone,birds:start.map(([fx,fy,t,f])=>{- const v=SPD*S*f;return{x:hw*(.08+.84*fx),y:H*(.08+.84*fy),vx:Math.cos(t)*v,vy:Math.sin(t)*v};})}));+ halves=[true,false].map(lone=>({W:hw,H:h,top,lone,birds:start.map(([fx,fy,t,f])=>{+ const v=SPD*S*f;return{x:hw*(.08+.84*fx),y:h*(.08+.84*fy),vx:Math.cos(t)*v,vy:Math.sin(t)*v};})}));halves.forEach(o=>inWorld(o,()=>{for(let i=0;i<180;i++)step(1);}));}-// Runs fn as if a world were the page's: its birds, size and rules (or none), nothing recorded, and the pointer in that half's own place+// Runs fn as if a world were the page's: its birds, size and rules (or none), nothing recorded, and the pointer in that world's own placefunction inWorld(o,fn){- const was=[birds,W,H,LONE,rec,ptr.x];- birds=o.birds;W=o.W;H=o.H;LONE=o.lone;rec=null;if(ptr.x>=o.W)ptr.x-=o.W;+ const was=[birds,W,H,LONE,rec,ptr.x,ptr.y];+ birds=o.birds;W=o.W;H=o.H;LONE=o.lone;rec=null;if(ptr.x>=o.W)ptr.x-=o.W;ptr.y-=o.top;fn();- [birds,W,H,LONE,rec,ptr.x]=was;+ [birds,W,H,LONE,rec,ptr.x,ptr.y]=was;}-// Each half is clipped to itself; a faint ring in both marks where the pointer is in its half, so both flee the same spot+// Each world is clipped to itself (below its half's name); a faint ring in both marks where the pointer is in its half, so both flee the same spotfunction drawHalves(){const hw=W/2;halves.forEach((o,i)=>{- ctx.save();ctx.beginPath();ctx.rect(i*hw,0,hw,H);ctx.clip();ctx.translate(i*hw,0);+ ctx.save();ctx.beginPath();ctx.rect(i*hw,o.top,hw,o.H);ctx.clip();ctx.translate(i*hw,o.top);inWorld(o,()=>{drawBirds();if(VIEW)drawView(!LONE,.55);@@ -397,7 +398,10 @@ const NOTES={inside:noteIn.textContent,compare:noteCmp.textContent,stillIn:'Shown still: one bird (orange) sees only the birds in its ring (the rest fade); its three pulls are keep apart (red), fly the same way (blue) and stay close (green).',stillCmp:'Shown still, from the same start: On their own, the birds have scattered every which way; As a flock, they fly in groups.'};const reduced=matchMedia('(prefers-reduced-motion: reduce)');-function notes(){const still=paused&&reduced.matches;noteIn.textContent=still?NOTES.stillIn:NOTES.inside;noteCmp.textContent=still?NOTES.stillCmp:NOTES.compare;}+function notes(){ // written only when the words change, so the live region does not read a note again at every Pause and Play+ const still=paused&&reduced.matches,put=(el,t)=>{if(el.textContent!==t)el.textContent=t;};+ put(noteIn,still?NOTES.stillIn:NOTES.inside);put(noteCmp,still?NOTES.stillCmp:NOTES.compare);+}reduced.addEventListener('change',notes);// Setting the canvas size wipes it, so a real change of the stage's size draws the flock again at once: the first starts the flock,@@ -410,7 +414,7 @@ function resize(){const dpr=Math.min(window.devicePixelRatio||1,2);cvs.width=W*dpr;cvs.height=H*dpr;ctx.setTransform(dpr,0,0,dpr,0,0);if(halves)makeHalves();- if(birds.length)draw();else spawn();+ if(birds.length){if(paused&&mode==='inside')step(0);draw();}else spawn(); // paused See inside works its pulls out again for the new size}// The pointer is recorded even while paused; the birds react to it only when they move (a paused Compare moves its rings). A mouse