Generates a plasma fractal grid of points using the Diamond Square algorithm.
From Wikipedia:
The diamond-square algorithm is a method for generating heightmaps for computer graphics. It is a slightly better algorithm than the three-dimensional implementation of the midpoint displacement algorithm which produces two-dimensional landscapes. It is also known as the random midpoint displacement fractal, the cloud fractal or the plasma fractal, because of the plasma effect produced when applied.
Starting with 4 corner points of random values, the algorithm fills in the grid, recursively, filling in detail iteratively. Each step references points from the previous step, adding a small amount of noise, reducing the noise at each iteration.
This results in a grid height-map which resembles mountainous terrain.
The grid is defined using an n
iteration value and the size of the grid equals 2^n + 1
.
If available in Hex, the package can be installed
by adding sesopenko_diamond_square
to your list of dependencies in mix.exs
:
def deps do
[
{:sesopenko_diamond_square, "~> 1.0.0"}
]
end
Documentation can be found at https://hexdocs.pm/sesopenko_diamond_square/api-reference.html.
Example of manually stepping through the algorithm:
my_diamond_square = Sesopenko.DiamondSquare.init(n)
{:ok, new_state} = Sesopenko.DiamondSquare.perform_step(my_diamond_square)
IO.puts(new_state.grid)
IO.puts(new_state.size)
Example of stepping to the end:
my_diamond_square = Sesopenko.DiamondSquare.init(n)
complete = Sesopenko.DiamondSquare.step_to_end(my_diamond_square)
IO.puts(new_state.grid)
IO.puts(new_state.size)
This is licensed GNU GPL V3. A copy of the license should be included in any distributions of this project. If not, an online copy of the GNU GPL V3 License may be referenced.