Maze generation: Difference between revisions

Content added Content deleted
m (javascript: minor clarification)
(Javascript: showing intermediate results)
Line 185:
| | | |
+---+---+---+---+---+---+---+---+---+---+---+</lang>
 
 
 
For an animated presentation of the progress of this maze creation process, you can use <code>display</code> in each iteration of the main loop. You would also need to take steps to make sure you could see each intermediate result.
 
For example, change replace the line <code>while (0<n) {</code> with:
 
<lang javascript> function step() {
if (0<n) {</lang>
 
And replace the closing brace for this while loop with:
 
<lang javascript> document.getElementById('out').innerHTML= display({x: x, y: y, horiz: horiz, verti: verti, here: here});
setTimeout(step, 100);
}
}
step();</lang>
 
To better see the progress, you might want a marker in place, showing the position being considered. To do that, replace the line which reads <code>if (0 == k%4) {</code> with
 
<lang javascript> if (m.here && m.here[0]*2+1 == j && m.here[1]*4+2 == k)
line[k]= '#'
else if (0 == k%4) {</lang>
 
Note however that this leaves the final '#' in place on maze completion, and that the function <code>maze</code> no longer returns a result which represents a generated maze.
 
=={{header|PicoLisp}}==