Animate thousands of points with canvas and D3
This block animates 7,000 colored points between five different layouts—sine wave, phyllotaxis spiral, spiral, and grid—using canvas and D3. Each point stores its current position, and when the user clicks, the `animate` function captures the start and target positions, then uses d3-timer and d3-ease to interpolate over 1.5 seconds before drawing the points to a 2D canvas context. The layouts are generated by mutating the x and y properties of the points array with functions like `sineLayout`, `phyllotaxisLayout`, and `gridLayout`. The canvas is scaled to the device pixel ratio for crisp rendering, and clicking the canvas stops the animation and shows a play control. The example is from a Bocoup blog post about smoothly animating thousands of points with HTML5 canvas and D3.
AI-generated descriptionAnimate thousands of points with canvas and D3
Using D3 and d3-transition works great when animating hundreds of points with SVG, but performance breaks down when you need to animate more than a thousand. This block demonstrates a simple approach to animating thousands of points between different layouts using canvas, d3-timer, and d3-ease.
See the blog post for more details.