Skip to main content
100%

Painting Euclidian Voronoi

✓ Published0🌍 Public
PPhilippe Rivière
Last edited Oct 15, 2016
Created on Oct 14, 2016

This example paints a Euclidean Voronoi diagram pixel by pixel onto a canvas, with each pixel colored according to its nearest site among 400 randomly placed points. A white overlay of the true Voronoi cell boundaries, computed with `d3.voronoi().polygons()`, is drawn after the painting finishes. The rendering uses an `O(n*x*y)` brute-force scan, computing squared Euclidean distances with `d3.scan()` and filling one vertical strip per pixel column. Site markers are drawn with colored strokes using Canvas 2D methods.

AI-generated description

By far the simplest of Voronoi algorithms is to paint pixels according to the color of their closest site. Such a shader will work with any definition of distance, weighted or not. Speed is awfully slow, in O(n*x*y). The results are pixels (canvas), not an abstract layout — we overlay it at the end.

See also <a href='http://bl.ocks.org/Fil/a7495ca3d5b322a6697530feb62fceef'>Painting Manhattan-distance Voronoi</a>.

mit Licensed

Similar vizzes