Skip to main content
100%

Painting Manhattan-distance Voronoi

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

This example paints a canvas pixel-by-pixel to show the Manhattan-distance Voronoi diagram of 400 random points. Each pixel receives the color of its nearest site, revealing diamond-shaped cell boundaries. The rendering iterates over every pixel sequentially using a `d3.interval`, computing the Manhattan distance via a custom function and selecting the closest site with `d3.scan`. The sites are drawn as white crosses on top of the colored cells, and the animation pauses after 30 seconds or when all pixels are processed.

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.

See also <a href='http://bl.ocks.org/Fil/f0fc1cf9afc96b591e3615563ece04cd'>Painting Euclidian Voronoi</a>.

mit Licensed

Similar vizzes