mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-20 02:51:23 +01:00
requested changes
This commit is contained in:
parent
8f78e460fe
commit
6b5d3fd67e
3 changed files with 39 additions and 32 deletions
|
|
@ -1,22 +1,16 @@
|
||||||
import { getGridPolygon } from "utils/graphUtils";
|
import { byId } from "utils/nodeUtils";
|
||||||
import { P, normalize, rn, last } from "utils";
|
|
||||||
import { clipPoly } from "utils/lineUtils";
|
|
||||||
import { ERROR } from "config/logging";
|
|
||||||
import * as d3 from "d3";
|
|
||||||
|
|
||||||
export function drawIce() {
|
export function drawIce() {
|
||||||
const ice = d3.select("#ice");
|
const ice = byId("ice");
|
||||||
const { ice: icePack } = pack;
|
const { ice: icePack } = pack;
|
||||||
|
|
||||||
|
let innerHTML = "";
|
||||||
for (const shield of icePack.iceShields) {
|
for (const shield of icePack.iceShields) {
|
||||||
ice
|
innerHTML += `<polygon points="${shield.points.toString()}" />`;
|
||||||
.append("polygon")
|
|
||||||
.attr("points", shield.points.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const iceberg of icePack.icebergs) {
|
for (const iceberg of icePack.icebergs) {
|
||||||
ice
|
innerHTML += `<polygon points="${iceberg.points.toString()}" />`;
|
||||||
.append("polygon")
|
|
||||||
.attr("points", iceberg.points.toString())
|
|
||||||
}
|
}
|
||||||
|
ice.innerHTML = innerHTML;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { ERROR } from "config/logging";
|
import { ERROR } from "config/logging";
|
||||||
import { aleaPRNG } from "scripts/aleaPRNG";
|
import { aleaPRNG } from "scripts/aleaPRNG";
|
||||||
import { IIce, Iiceberg } from "types/pack/ice";
|
|
||||||
import { clipPoly, last, normalize, P, rn } from "utils";
|
import { clipPoly, last, normalize, P, rn } from "utils";
|
||||||
|
|
||||||
export function generateIce(
|
export function generateIce(
|
||||||
|
|
@ -8,7 +7,7 @@ export function generateIce(
|
||||||
vertices: IGraphVertices,
|
vertices: IGraphVertices,
|
||||||
temp: Int8Array,
|
temp: Int8Array,
|
||||||
features: TGridFeatures,
|
features: TGridFeatures,
|
||||||
gridCells: Pick<IGrid["cells"], "f" | "t">,
|
gridCells: Pick<IGrid["cells"], "f" | "t">
|
||||||
): IIce {
|
): IIce {
|
||||||
const shieldMin = -8; // max temp to form ice shield (glacier)
|
const shieldMin = -8; // max temp to form ice shield (glacier)
|
||||||
const icebergMax = 1; // max temp to form an iceberg
|
const icebergMax = 1; // max temp to form an iceberg
|
||||||
|
|
@ -34,12 +33,16 @@ export function generateIce(
|
||||||
const chain = connectVertices(vertex);
|
const chain = connectVertices(vertex);
|
||||||
if (chain.length < 3) continue;
|
if (chain.length < 3) continue;
|
||||||
const points = clipPoly(chain.map((v) => vertices.p[v]));
|
const points = clipPoly(chain.map((v) => vertices.p[v]));
|
||||||
icePack.iceShields.push({ points, type: "iceShield" });
|
icePack.iceShields.push({ points, transform: { x: 0, y: 0 } });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// mildly cold: iceberd
|
// mildly cold: iceberd
|
||||||
if (P(normalize(temperature, -7, 2.5))) continue; // t[-5; 2] cold: skip some cells
|
if (P(normalize(temperature, -7, 2.5))) continue; // t[-5; 2] cold: skip some cells
|
||||||
if (gridCells.f[i] !== 0 && (features[gridCells.f[i]] as IGridFeature).type === "lake") continue; // lake: no icebers // MARKER as IGridFeature
|
if (
|
||||||
|
gridCells.f[i] !== 0 &&
|
||||||
|
(features[gridCells.f[i]] as IGridFeature).type === "lake"
|
||||||
|
)
|
||||||
|
continue; // lake: no icebers // MARKER as IGridFeature
|
||||||
let size = (6.5 + temperature) / 10; // iceberg size: 0 = full size, 1 = zero size
|
let size = (6.5 + temperature) / 10; // iceberg size: 0 = full size, 1 = zero size
|
||||||
if (gridCells.t[i] === -1) size *= 1.3; // coasline: smaller icebers
|
if (gridCells.t[i] === -1) size *= 1.3; // coasline: smaller icebers
|
||||||
size = Math.min(size * (0.4 + Math.random() * 1.2), 0.95); // randomize iceberg size
|
size = Math.min(size * (0.4 + Math.random() * 1.2), 0.95); // randomize iceberg size
|
||||||
|
|
@ -48,13 +51,20 @@ export function generateIce(
|
||||||
return icePack;
|
return icePack;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
function generateIceberg(i: number, size: number): Iiceberg {
|
function generateIceberg(i: number, size: number): IiceBerg {
|
||||||
const cellMidPoint = cells.p[i];
|
const cellMidPoint = cells.p[i];
|
||||||
const points = cells.v[i].map(v => vertices.p[v]).map((point) => [
|
const points: TPoints = cells.v[i]
|
||||||
|
.map((v) => vertices.p[v])
|
||||||
|
.map((point) => [
|
||||||
(point[0] + (cellMidPoint[0] - point[0]) * size) | 0,
|
(point[0] + (cellMidPoint[0] - point[0]) * size) | 0,
|
||||||
(point[1] + (cellMidPoint[1] - point[1]) * size) | 0,
|
(point[1] + (cellMidPoint[1] - point[1]) * size) | 0,
|
||||||
]);
|
]);
|
||||||
return { points, cell: i, size: rn(1 - size, 2) };
|
return {
|
||||||
|
points,
|
||||||
|
transform: { x: 0, y: 0 },
|
||||||
|
cell: i,
|
||||||
|
size: rn(1 - size, 2),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect vertices to chain
|
// connect vertices to chain
|
||||||
|
|
@ -71,9 +81,12 @@ export function generateIce(
|
||||||
currentVertex
|
currentVertex
|
||||||
.filter((cellIndicie) => temp[cellIndicie] <= shieldMin)
|
.filter((cellIndicie) => temp[cellIndicie] <= shieldMin)
|
||||||
.forEach((cellIndice) => (used[cellIndice] = 1));
|
.forEach((cellIndice) => (used[cellIndice] = 1));
|
||||||
const c0 = currentVertex[0] >= nOfCells || temp[currentVertex[0]] > shieldMin;
|
const c0 =
|
||||||
const c1 = currentVertex[1] >= nOfCells || temp[currentVertex[1]] > shieldMin;
|
currentVertex[0] >= nOfCells || temp[currentVertex[0]] > shieldMin;
|
||||||
const c2 = currentVertex[2] >= nOfCells || temp[currentVertex[2]] > shieldMin;
|
const c1 =
|
||||||
|
currentVertex[1] >= nOfCells || temp[currentVertex[1]] > shieldMin;
|
||||||
|
const c2 =
|
||||||
|
currentVertex[2] >= nOfCells || temp[currentVertex[2]] > shieldMin;
|
||||||
const vertexNeighbors = vertices.v[current]; // neighboring vertices
|
const vertexNeighbors = vertices.v[current]; // neighboring vertices
|
||||||
if (vertexNeighbors[0] !== prev && c0 !== c1)
|
if (vertexNeighbors[0] !== prev && c0 !== c1)
|
||||||
current = vertexNeighbors[0];
|
current = vertexNeighbors[0];
|
||||||
|
|
|
||||||
14
src/types/pack/ice.d.ts
vendored
14
src/types/pack/ice.d.ts
vendored
|
|
@ -1,18 +1,18 @@
|
||||||
|
|
||||||
export interface IIceBase {
|
interface IIceBase {
|
||||||
points: number[][];
|
points: TPoints;
|
||||||
|
transform: {x: number, y: number};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Iiceberg extends IIceBase {
|
interface IiceBerg extends IIceBase {
|
||||||
cell: number;
|
cell: number;
|
||||||
size: number;
|
size: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IiceShield extends IIceBase {
|
interface IiceShield extends IIceBase {
|
||||||
type: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IIce{
|
interface IIce{
|
||||||
icebergs: Iiceberg[];
|
icebergs: IiceBerg[];
|
||||||
iceShields: IiceShield[];
|
iceShields: IiceShield[];
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue