generateHeightmap = (nbIters, seed, { p1 = 0.5, p2 = 1.1 } = {}) => {
const prng = minstRand0(seed);
let H = [
[prng(), prng()],
[prng(), prng()]
];
let f = p1;
for (let n = 0; n < nbIters; n++) {
let f2 = 2 * f;
H = spatialSubdivision(H, function () {
return prng() * f2 - f;
});
f /= 2 ** p2;
}
const N = H.length;
console.log(N);
let [min, max] = [+Infinity, -Infinity];
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
let h = H[i][j];
min = Math.min(min, h);
max = Math.max(max, h);
}
}
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
H[i][j] -= min;
}
}
return { heightmap: H, max: max - min };
}