Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Mapfill_Heightmap_Fractal(Randomness, Seed)
- local Chunk_Size = 16
- -- Fill it with random start values
- local Size = 2 -- SIZE OF THE RANDOM ARRAY
- local Heightmap = CREATE SOME RANDOM ARRAY HERE, ATLEAST 2x2 !!!!!!!!!!!!!!!!!!!!!!
- -- Do the iterations
- while Size < Chunk_Size do
- -- Resize the array
- for ix = Size+1, Size*2 do
- Heightmap[ix] = {}
- --for iy = Size+1, Size*2 do
- -- Heightmap[ix][iy] = 0
- --end
- end
- for ix = Size, 0, -1 do
- for iy = Size, 0, -1 do
- Heightmap[ix*2][iy*2] = Heightmap[ix][iy]
- end
- end
- Size = Size * 2
- -- The diamond step
- for ix = 1, Size, 2 do
- for iy = 1, Size, 2 do
- Heightmap[ix][iy] = (Heightmap[ix+1][iy+1] + Heightmap[ix-1][iy+1] + Heightmap[ix+1][iy-1] + Heightmap[ix-1][iy-1]) / 4
- end
- end
- -- The square step
- for ix = 0, Size, 2 do
- for iy = 1, Size, 2 do
- Heightmap[ix][iy] = (Heightmap[ix][iy-1] + Heightmap[ix][iy+1]) / 2
- end
- end
- for ix = 1, Size, 2 do
- for iy = 0, Size, 2 do
- Heightmap[ix][iy] = (Heightmap[ix-1][iy] + Heightmap[ix+1][iy]) / 2
- end
- end
- end
- -- Return the Heightmap
- return Heightmap
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement