🎯 K-Means Clustering (2D) — Lloyd's Algorithm
A 2D canvas simulation showing k-means clustering: points are assigned to the nearest centroid and centroids move to the cluster mean until the assignment stops changing.
This 2D companion runs the same Lloyd's-algorithm loop as the 3D version on a plain canvas: click to add points, pick a k, and watch the two-step iteration — assign every point to its nearest centroid, then move each centroid to the mean of its assigned points — carve the plane into Voronoi cells that settle as inertia (the sum of squared distances from each point to its centroid) falls. A k-means++ toggle lets you compare seeding strategies, and the Blobs/Moons preset makes clear where k-means succeeds (round, similarly-sized clusters) and where it struggles (the interleaving Moons shapes).
A 2D canvas simulation showing k-means clustering: points are assigned to the nearest centroid and centroids move to the cluster mean until the assignment stops changing.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install