diff --git a/simplex.lua b/simplex.lua index e10e60a..90c2ae1 100644 --- a/simplex.lua +++ b/simplex.lua @@ -556,4 +556,21 @@ function simplex.Seed(seed) end end +-- TODO test functionality +function simplex.FractalBrownianMotion2D(x, y, octaves, lacunarity, gain) + octaves = octaves or 4 + lacunarity = lacunarity or 2 + gain = gain or 0.5 + + local total, amplitude, frequency, peak_amplitude = 0, 1, 1, 0 + for i = 1, octaves do + total = total + amplitude * simplex.Noise2D(x * frequency, y * frequency) + peak_amplitude = peak_amplitude + amplitude + amplitude = amplitude * gain + frequency = frequency * lacunarity + end + + return total / peak_amplitude -- normalize to [-1, 1] +end + return simplex