mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
addLakesInDeepDepressions
This commit is contained in:
parent
6cca0b7f38
commit
c8c1c24909
5 changed files with 113 additions and 39 deletions
|
|
@ -1,8 +1,7 @@
|
|||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.OceanLayers = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
typeof exports === "object" && typeof module !== "undefined" ? (module.exports = factory()) : typeof define === "function" && define.amd ? define(factory) : (global.OceanLayers = factory());
|
||||
})(this, function () {
|
||||
"use strict";
|
||||
|
||||
let cells, vertices, pointsN, used;
|
||||
|
||||
|
|
@ -12,11 +11,11 @@
|
|||
TIME && console.time("drawOceanLayers");
|
||||
|
||||
lineGen.curve(d3.curveBasisClosed);
|
||||
cells = grid.cells, pointsN = grid.cells.i.length, vertices = grid.vertices;
|
||||
(cells = grid.cells), (pointsN = grid.cells.i.length), (vertices = grid.vertices);
|
||||
const limits = outline === "random" ? randomizeOutline() : outline.split(",").map(s => +s);
|
||||
|
||||
const chains = [];
|
||||
const opacity = rn(.4 / limits.length, 2);
|
||||
const opacity = rn(0.4 / limits.length, 2);
|
||||
used = new Uint8Array(pointsN); // to detect already passed cells
|
||||
|
||||
for (const i of cells.i) {
|
||||
|
|
@ -29,10 +28,13 @@
|
|||
const chain = connectVertices(start, t); // vertices chain to form a path
|
||||
if (chain.length < 4) continue;
|
||||
const relax = 1 + t * -2; // select only n-th point
|
||||
const relaxed = chain.filter((v, i) => !(i%relax) || vertices.c[v].some(c => c >= pointsN));
|
||||
const relaxed = chain.filter((v, i) => !(i % relax) || vertices.c[v].some(c => c >= pointsN));
|
||||
if (relaxed.length < 4) continue;
|
||||
const points = clipPoly(relaxed.map(v => vertices.p[v]), 1);
|
||||
chains.push([t, points]);
|
||||
const points = clipPoly(
|
||||
relaxed.map(v => vertices.p[v]),
|
||||
1
|
||||
);
|
||||
chains.push([t, points]);
|
||||
}
|
||||
|
||||
for (const t of limits) {
|
||||
|
|
@ -48,14 +50,18 @@
|
|||
}
|
||||
|
||||
TIME && console.timeEnd("drawOceanLayers");
|
||||
}
|
||||
};
|
||||
|
||||
function randomizeOutline() {
|
||||
const limits = [];
|
||||
let odd = .2
|
||||
let odd = 0.2;
|
||||
for (let l = -9; l < 0; l++) {
|
||||
if (P(odd)) {odd = .2; limits.push(l);}
|
||||
else {odd *= 2;}
|
||||
if (P(odd)) {
|
||||
odd = 0.2;
|
||||
limits.push(l);
|
||||
} else {
|
||||
odd *= 2;
|
||||
}
|
||||
}
|
||||
return limits;
|
||||
}
|
||||
|
|
@ -63,24 +69,26 @@
|
|||
// connect vertices to chain
|
||||
function connectVertices(start, t) {
|
||||
const chain = []; // vertices chain to form a path
|
||||
for (let i=0, current = start; i === 0 || current !== start && i < 10000; i++) {
|
||||
for (let i = 0, current = start; i === 0 || (current !== start && i < 10000); i++) {
|
||||
const prev = chain[chain.length - 1]; // previous vertex in chain
|
||||
chain.push(current); // add current vertex to sequence
|
||||
const c = vertices.c[current]; // cells adjacent to vertex
|
||||
c.filter(c => cells.t[c] === t).forEach(c => used[c] = 1);
|
||||
c.filter(c => cells.t[c] === t).forEach(c => (used[c] = 1));
|
||||
const v = vertices.v[current]; // neighboring vertices
|
||||
const c0 = !cells.t[c[0]] || cells.t[c[0]] === t-1;
|
||||
const c1 = !cells.t[c[1]] || cells.t[c[1]] === t-1;
|
||||
const c2 = !cells.t[c[2]] || cells.t[c[2]] === t-1;
|
||||
const c0 = !cells.t[c[0]] || cells.t[c[0]] === t - 1;
|
||||
const c1 = !cells.t[c[1]] || cells.t[c[1]] === t - 1;
|
||||
const c2 = !cells.t[c[2]] || cells.t[c[2]] === t - 1;
|
||||
if (v[0] !== undefined && v[0] !== prev && c0 !== c1) current = v[0];
|
||||
else if (v[1] !== undefined && v[1] !== prev && c1 !== c2) current = v[1];
|
||||
else if (v[2] !== undefined && v[2] !== prev && c0 !== c2) current = v[2];
|
||||
if (current === chain[chain.length - 1]) {ERROR && console.error("Next vertex is not found"); break;}
|
||||
if (current === chain[chain.length - 1]) {
|
||||
ERROR && console.error("Next vertex is not found");
|
||||
break;
|
||||
}
|
||||
}
|
||||
chain.push(chain[0]); // push first vertex as the last one
|
||||
return chain;
|
||||
}
|
||||
|
||||
return OceanLayers;
|
||||
|
||||
})));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue