Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created August 2, 2023 22:46
Show Gist options
  • Save mattdesl/8be43fdf7beec4e5294a21f57020ae5f to your computer and use it in GitHub Desktop.
Save mattdesl/8be43fdf7beec4e5294a21f57020ae5f to your computer and use it in GitHub Desktop.

Revisions

  1. mattdesl created this gist Aug 2, 2023.
    14 changes: 14 additions & 0 deletions fractal-noise.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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;
    }