Quadtree Expansion Applet

This Java applet is an interactive version of the quadtree used in the Terrapin terrain algorithm. This is on a square mesh, and I've switched to a triangular mesh in the terrain generator, but it's otherwise a very similar algorithm. Left-clicking on a cell expands it one level of detail, and right-clicking collapses it one level.

Adjacent cells are only allowed to differ by one level of detail. The details of the terrain fractal require this. This means when a cell is expanded, other adjacent cells may also have to be expanded. Similarly, a cell can't be collapsed unless this rule is still obeyed after the collapse. Cells with frustrated collapses pending the collapse of adjacent cells are drawn in yellow; in this applet, and in the actual terrain generator, such cells will automatically collapse once the necessary adjacent collapses have occurred.