Files
bworld/tools/noise_quantiles.ts
T
2026-09-25 17:14:26 -03:00

25 lines
1019 B
TypeScript

// measures the percentiles of octave noise, for the Quantiles tables in common/worldgen/terrain.ts.
// they only depend on the amplitudes. deno run tools/noise_quantiles.ts '[1,1,2,2,1,1]' '[1,2,1]'
import { OctaveNoise2D } from "$/common/worldgen/noise.ts";
const SAMPLES_PER_SEED = 20000;
const SEEDS = 20;
for (const arg of Deno.args) {
const amplitudes = JSON.parse(arg) as number[];
const values: number[] = [];
for (let s = 0; s < SEEDS; s++) {
const noise = new OctaveNoise2D(`quantiles${s}`, "n", 1, amplitudes);
for (let i = 0; i < SAMPLES_PER_SEED; i++) {
// far apart compared to the wavelength of 1, so samples don't correlate
values.push(noise.sample(i * 7.31 + s * 1000, i * 3.17 - s * 500));
}
}
values.sort((a, b) => a - b);
const table = Array.from({ length: 21 }, (_, i) => {
const index = Math.min(values.length - 1, Math.round((i / 20) * (values.length - 1)));
return Number(values[index].toFixed(4));
});
console.log(JSON.stringify(amplitudes), JSON.stringify(table));
}