Recreating Complex Web Particle Animations: How They Work and How to Rebuild Them with AI
Scroll-driven particle animations are a staple of modern product and brand landing pages. This article breaks one down into five manageable modules: a particle system, offscreen-canvas shape sampling, lerp-based interpolation, scroll-progress mapping, and mouse repulsion physics. You will see working JavaScript for each layer, a set of practical performance optimizations (WebGL rendering, offscreen caching and Web Workers, adaptive quality, visibility pausing, event throttling), and a workflow for using AI coding tools to recreate the effect: state the goal rather than the implementation, split the work into verifiable milestones, provide a reference, and prioritize fidelity. The article closes with four criteria for judging a recreation and a version-by-version comparison habit that keeps the result converging on the original.
1. Why These Animations Are Worth Taking Apart
Product sites and brand landing pages increasingly use “particles converging” as their above-the-fold visual language. On page load, thousands of points scatter like a starfield. As the user scrolls, those points drift toward the center and gradually trace out a shape with brand recognition — a number, an icon, a logo. When the mouse passes over them, the particles scatter as if disturbed by gravity, then slowly return once the cursor leaves.
The effect combines narrative and immersion, which makes it a classic test case for front-end animation skills. It looks flashy, but it can be broken down into a small set of clear technical modules. Once you understand the mechanics, you can build it yourself or reproduce it with the help of AI coding tools, in either case with a concrete plan rather than guesswork.
2. Core Mechanics
2.1 What a particle system actually is
Everything rests on the particle system. Each particle can be understood as a data object carrying position and velocity:
class Particle {constructor(x, y) {this.x = x; // current positionthis.y = y;this.targetX = x; // target position (after convergence)this.targetY = y;this.vx = 0; // velocity, used for physics interactionsthis.vy = 0;}}
Thousands of these objects form the particle collection, and every frame their positions are updated by rules and then redrawn. There are two common choices for the rendering layer: Canvas 2D suits small to medium scale (a few thousand particles), while WebGL renders in parallel on the GPU and can comfortably handle six-figure particle counts while staying smooth.
2.2 Sampling the target shape: where each point should go
To make scattered particles converge into a specific shape, the key step is sampling — extracting a set of coordinate points from the target shape to serve as each particle’s destination. The most common approach in practice is reading pixels from an offscreen canvas:
function sampleShapePoints(drawShape, sampleCount) {const off = document.createElement('canvas');const ctx = off.getContext('2d');drawShape(ctx); // draw the target shape onto the offscreen canvasconst { data } = ctx.getImageData(0, 0, off.width, off.height);const candidates = [];for (let i = 0; i < data.length; i += 4) {if (data[i + 3] > 128) { // non-transparent pixels belong to the shapeconst idx = i / 4;candidates.push({x: idx % off.width,y: Math.floor(idx / off.width)});}}// randomly / evenly pick from the candidates to avoid overly dense clustersreturn shuffle(candidates).slice(0, sampleCount);}
Once sampling is done, assign these coordinates to each particle’s targetX / targetY, and the particles now have an explicit destination.
2.3 Animation loop and interpolation
Each frame, linear interpolation (lerp) moves particles smoothly toward their targets. This is the soul of the convergence effect:
function animate() {particles.forEach(p => {p.x += (p.targetX - p.x) * 0.08; // the coefficient controls convergence speedp.y += (p.targetY - p.y) * 0.08;});render();requestAnimationFrame(animate);}
For a more natural feel, you can introduce an easing function (ease-out) or a spring damping model so particles bounce slightly as they approach their targets. The result looks more refined.
2.4 Driving the transition with scroll progress: from star points to shape
The switch between converging and scattering is driven by scroll progress (0 to 1) under the hood. Interpolating between multiple sets of targets by progress is all it takes:
window.addEventListener('scroll', () => {const maxScroll = document.body.scrollHeight - window.innerHeight;const progress = window.scrollY / maxScroll; // normalized to 0~1particles.forEach((p, i) => {p.targetX = lerp(scatterX[i], shapeX[i], progress);p.targetY = lerp(scatterY[i], shapeY[i], progress);});});
At progress 0 the particles are scattered (random star points); at progress 1 they have fully converged into the target shape; everything in between is smoothed by interpolation.
2.5 Mouse interaction: simulating a gravity disturbance
The sense of disturbance when the mouse passes over comes from a simple repulsion model: the closer a particle is to the cursor, the stronger the push it receives.
particles.forEach(p => {const dx = p.x - mouse.x;const dy = p.y - mouse.y;const dist = Math.hypot(dx, dy) || 1;const radius = 120;if (dist < radius) {const force = (radius - dist) / radius; // the closer, the stronger the forcep.x += (dx / dist) * force * 15;p.y += (dy / dist) * force * 15;}});
Because interpolation still pulls particles back toward their targets on every frame, they return to place automatically once the mouse leaves, producing a pleasing “disturb — recover” cycle.
3. Performance Optimization
The bottlenecks in animations like this usually sit at both ends: rendering and computation. Optimizations worth considering:
- Rendering approach: at tens of thousands of particles, switch to WebGL or texture-based batched rendering instead of drawing point by point.
- Compute isolation: move sampling and coordinate calculations into an offscreen cache or a Web Worker so they do not block the main thread.
- Graceful degradation: detect device performance and adjust particle count and frame rate adaptively; reduce precision automatically on weaker devices.
- Pause when hidden: stop the animation loop when the page is not visible to save resources.
- Event throttling: throttle or debounce scroll and mouse events to avoid jitter from high-frequency triggers.
4. Rebuilding the Effect with AI Coding Tools
In real projects, many developers use AI coding tools to speed up the recreation of effects like this. Getting high-quality output depends heavily on how clearly the prompt is written:
- State the goal, not the method. Describe what should be achieved (converge on scroll, scatter into star points, respond to the mouse) rather than prescribing implementation details, leaving the tool room to choose a better approach.
- Break it into verifiable sub-goals. First have it build the basic particle system and single-shape convergence, then add the scroll-driven switch, then the mouse interaction. Converging step by step makes problems easy to locate.
- Provide a reference. If the effect comes from a particular page, let the tool use its built-in browsing capability to load the page, read its source, or analyze a screenshot for clues, which reduces blind guessing.
- Prioritize fidelity. When the goal is to recreate rather than innovate, state explicitly that the result should stay as close as possible to the original effect, so the tool does not wander off in a different direction.
One thing to watch: the scripts on a page being recreated are often minified and code-split, which makes the source hard to read, and grabbing it directly may not recover the logic at all. In that case, “observe screenshots + rebuild with parameters” is usually more effective than “copy the source line by line” — that is, first observe the key parameters of the animation (particle count, convergence speed, disturbance radius), then rebuild an equivalent implementation based on the principles described above.
5. Evaluating the Recreation
Four dimensions tell you whether a recreation succeeded:
- Shape consistency: does the converged shape match the target in proportions and position?
- Animation smoothness: are the converge/scatter transitions smooth, without frame skips or stutter?
- Interaction naturalness: do the mouse disturbance and return feel fluid, without stiffness?
- Performance stability: is the frame rate stable across mainstream devices and resolutions?
It is worth building a habit of version-by-version comparison: have the tool produce a baseline version first, then iterate round by round while diffing against the original effect, rather than expecting everything to land in one shot. Most of the gap in an animation hides in the detail parameters, and only several rounds of fine-tuning will close it.
