k-means alternates assign — every point picks its nearest centroid — and update — every centroid moves to its cluster's mean — until nothing changes. It's greedy and gets stuck in local minima, so the initialization matters: Forgy picks k random points, k-means++ spreads seeds by squared distance to reduce bad starts. Click below to paint your own points, then step through the Lloyd iterations.
Colored regions = Voronoi cells for the current centroids. Circle × = centroid.
Plain Forgy picks k data points uniformly at random, which occasionally lumps two seeds into the same true cluster — the algorithm converges to a local minimum that splits one cluster while merging two others. k-means++ seeds the first centroid uniformly, then each subsequent seed is drawn with probability proportional to D(x)², where D(x) is the distance from x to the nearest already-picked seed. This guarantees an expected O(log k) approximation to the optimal WCSS, and in practice cuts iterations roughly in half. Try both on the "concentric rings" preset — k-means simply can't cluster non-convex shapes no matter how you seed it, which is why you'd reach for DBSCAN or spectral clustering instead.