That code does NOT implement Prim's algorithm on a graph with randomly-weighted edges. Instead it just does a randomized breadth-first search of the area (starting from the corner), which is the same algorithm used for colouring, which is why the radial pattern occurs.<p>For a randomized spanning tree, edges should be generated with a random weight, and Prim's algorithm extracts them from the frontier ordered by weight. This creates a very different tree structure that is much more similar to the uniform spanning tree generated by Wilson's algorithm.<p>(This comment is based on the code from this page: <a href="http://bl.ocks.org/mbostock/11159599" rel="nofollow">http://bl.ocks.org/mbostock/11159599</a>)
Here’s my version of this from last year: <a href="http://bl.ocks.org/robinhouston/6027749" rel="nofollow">http://bl.ocks.org/robinhouston/6027749</a>
Looks cool. The article could use a bit more explanation of what exactly I'm looking at.<p>Is this is a flood-fill algorithm?<p>Cause what I remember from back in the day when you could still watch MS Paint do the flood fill, a more efficient version fills out horizontal spans all at once, instead of growing like an ink blot.<p>But it looks cool.<p><i>EDIT:</i> maybe this is one of those "use the entire RGB colour space" type of renderings? (see <a href="http://allrgb.com" rel="nofollow">http://allrgb.com</a> )
You could use an transferable typed array buffer instead of copying an array of integers from the worker thread. Looks like the array is under 4mb, so copying doesn't take very long, and you only do it once, but if you're going to use a worker you might as well.<p><a href="http://updates.html5rocks.com/2011/12/Transferable-Objects-Lightning-Fast" rel="nofollow">http://updates.html5rocks.com/2011/12/Transferable-Objects-L...</a>
It would be cool to visualize the depth with a colormap that makes it visually possible to compare depths, e.g. Matlab's Hot. HSV colormaps are pretty but make direct visual comparisons difficult [1].<p>[1] <a href="http://people.renci.org/~borland/pdfs/RainbowColorMap_VisViewpoints.pdf" rel="nofollow">http://people.renci.org/~borland/pdfs/RainbowColorMap_VisVie...</a>
the point of Wilson's algorithm is that each spanning is equally likely.<p>Each tree is selected uniformly amoug the HUGE set of possible spanning trees of this graph.<p>The color patterns in this algorithm vs. Prim algorithm are very different. Unlike Prim algorithm, this pattern is random and has a fractal structure.<p>Is there a good reason a programmer might need each UST to be equally likely?
I love mike bostock's stuff, but his code often makes me feel sorry for whoever has to deal with his code after him<p><pre><code> // Pick a location that’s not yet in the maze (if any).
do if ((index0 = remaining.pop()) == null) return true;
while (cells[index0] >= 0);
// Perform a random walk starting at this location,
previous[index0] = index0;
walk: while (true) {
i = index0 % width;
j = index0 / width | 0;
// picking a legal random direction at each step.
direction = Math.random() * 4 | 0;
if (direction === 0) { if (j <= 0) continue walk; --j; }
else if (direction === 1) { if (j >= height - 1) continue walk; ++j; }
else if (direction === 2) { if (i <= 0) continue walk; --i; }
else { if (i >= width - 1) continue walk; ++i; }
</code></pre>
note the braceless do while and the labeled jump statements