Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created August 2, 2023 22:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/8be43fdf7beec4e5294a21f57020ae5f to your computer and use it in GitHub Desktop.
Save mattdesl/8be43fdf7beec4e5294a21f57020ae5f to your computer and use it in GitHub Desktop.
function fractalNoise(x, y, frequency, octaves, persistence = 0.5, lacunarity = 2) {
let total = 0;
let amplitude = 1;
let maxValue = 0; // Used for normalizing result to 0.0 - 1.0
for (let i = 0; i < octaves; i++) {
total += noise2D(x * frequency, y * frequency) * amplitude;
maxValue += amplitude;
amplitude *= persistence;
frequency *= lacunarity;
}
return total / maxValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment