add FractalBrownianMotion2D function

needs testing
This commit is contained in:
2026-08-15 03:13:42 -06:00
parent 5e10e36d48
commit f0f9654910
+17
View File
@@ -556,4 +556,21 @@ function simplex.Seed(seed)
end end
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 return simplex