reset PRNG - make points generation deterministic

This commit is contained in:
Azgaar 2021-09-16 11:59:00 +03:00
parent a9755dacc8
commit 6a6ba96c96
2 changed files with 3 additions and 1 deletions

View file

@ -669,6 +669,7 @@ function generateSeed() {
// Place points to calculate Voronoi diagram // Place points to calculate Voronoi diagram
function placePoints() { function placePoints() {
TIME && console.time("placePoints"); TIME && console.time("placePoints");
Math.random = aleaPRNG(seed); // reset PRNG
const cellsDesired = +pointsInput.dataset.cells; const cellsDesired = +pointsInput.dataset.cells;
const spacing = (grid.spacing = rn(Math.sqrt((graphWidth * graphHeight) / cellsDesired), 2)); // spacing between points before jirrering const spacing = (grid.spacing = rn(Math.sqrt((graphWidth * graphHeight) / cellsDesired), 2)); // spacing between points before jirrering

View file

@ -25,7 +25,8 @@ function getBoundaryPoints(width, height, spacing) {
function getJitteredGrid(width, height, spacing) { function getJitteredGrid(width, height, spacing) {
const radius = spacing / 2; // square radius const radius = spacing / 2; // square radius
const jittering = radius * 0.9; // max deviation const jittering = radius * 0.9; // max deviation
const jitter = () => Math.random() * 2 * jittering - jittering; const doubleJittering = jittering * 2;
const jitter = () => Math.random() * doubleJittering - jittering;
let points = []; let points = [];
for (let y = radius; y < height; y += spacing) { for (let y = radius; y < height; y += spacing) {