Inspirational 3-dimensional world generation and visualization with tunable parameters as a three dimensional map rendered with pure Javascript in the browser.
This is a work in progress, but the generation mostly works as follows:
- We begin with a grid of randomized points.
- Those points are fed into Delaunator, a library for quickly generating Delaunay triangulations. For our purposes, this connects nearby points.
- From the triangulation, we build a graph of nodes from each raw point, containing default height information and links to the neighboring nodes. It's all graph traversal from here on out.
- Feature generation
- Randomly generate initial parameters. Peak or trough (below sea level), spread, ridge length, etc.
- Choose an initial starting point. Record its distance from the ridge line (as 0). Add it to our node queue.
- While the ridge length is less than the desired length, add a neighboring node we haven't seen to our node queue. If we're more than two nodes in, check all neighbors and find the node with the maximum angle between the incoming and outgoing edges. Record these distances as 0.
- Once we've collected our ridge, begin pulling nodes off the queue. Set the height based on our height falloff function. If the current distance is less than the maximum feature spread, add the neighboring nodes we haven't operated on yet to our queue. Mark their distances as the current distance plus one.