Scatter points, drop centroids, watch clusters crystallize.
K-means runs Lloyd's algorithm. After seeding k centroids (random or k-means++, which spreads seeds by distance), each iteration has two steps: assign every point to its nearest centroid (coloring the clusters), then update each centroid to the mean of the points it owns. The shaded Voronoi background shows which centroid currently owns each region. Inertia — the total within-cluster squared distance — drops every step until centroids stop moving and the run converges.
K-means is the workhorse of unsupervised learning: customer segmentation, image color quantization, vector quantization, and feature learning all lean on it. It is fast and intuitive, but it only finds a local optimum, assumes round clusters, and is sensitive to the seed — which is exactly why smarter initialization like k-means++ matters. Try the same points with different seeds and watch inertia land in different places.