From f0f9654910611f46fe33dec5db91036da713f8eb Mon Sep 17 00:00:00 2001 From: tangent Date: Sat, 15 Aug 2026 03:13:42 -0600 Subject: [PATCH] add FractalBrownianMotion2D function needs testing --- simplex.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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