Painting power diagram (weighted Voronoi)
This example paints a weighted Voronoi diagram by coloring each pixel according to the closest of 400 randomly placed sites, using a custom distance function that adds a weight to squared Euclidean distance. The rendering is done directly on a Canvas 2D context, scanning pixel by pixel with `d3.scan` to find the nearest site and filling vertical strips for speed. Sites with a weight of 200 appear with red crosses, while unweighted ones are marked white. The code uses D3 v4’s `d3.interval` for incremental drawing and `d3.scaleOrdinal` with `schemeCategory20b` to assign colors.
AI-generated descriptionWarning: unfinished & not verified!
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>.
forked from <a href='http://bl.ocks.org/Fil/'>Fil</a>'s block: <a href='http://bl.ocks.org/Fil/a7495ca3d5b322a6697530feb62fceef'>Painting Manhattan-distance Voronoi</a>