fix(#906): ice to follow expected size, reduce ice elements in general

This commit is contained in:
Azgaar 2023-02-25 16:01:22 +04:00
parent 89d61fda5f
commit f018256f7a
5 changed files with 29 additions and 27 deletions

View file

@ -2768,7 +2768,7 @@
<div id="iceEditor" class="dialog" style="display: none">
<button id="iceEditStyle" data-tip="Edit style in Style Editor" class="icon-brush"></button>
<button id="iceRandomize" data-tip="Randomize Iceberg shape" class="icon-shuffle"></button>
<input id="iceSize" data-tip="Change Iceberg size" type="range" min=".05" max="1" step=".01" />
<input id="iceSize" data-tip="Change Iceberg size" type="range" min=".05" max="2" step=".01" />
<button id="iceNew" data-tip="Add an Iceberg (click on map)" class="icon-plus"></button>
<button
id="iceRemove"
@ -7849,7 +7849,7 @@
<script src="utils/colorUtils.js"></script>
<script src="utils/graphUtils.js?v=1.88.02"></script>
<script src="utils/nodeUtils.js"></script>
<script src="utils/numberUtils.js"></script>
<script src="utils/numberUtils.js?v=1.89.08"></script>
<script src="utils/polyfills.js"></script>
<script src="utils/probabilityUtils.js?v=1.88.00"></script>
<script src="utils/stringUtils.js"></script>
@ -7860,7 +7860,7 @@
<script src="config/heightmap-templates.js"></script>
<script src="config/precreated-heightmaps.js"></script>
<script src="modules/heightmap-generator.js?v=1.88.00"></script>
<script src="modules/ocean-layers.js?v=1.87.15"></script>
<script src="modules/ocean-layers.js?v=1.89.08"></script>
<script src="modules/river-generator.js"></script>
<script src="modules/lakes.js"></script>
<script src="modules/names-generator.js?v=1.87.14"></script>
@ -7896,7 +7896,7 @@
<script defer src="modules/ui/elevation-profile.js"></script>
<script defer src="modules/ui/temperature-graph.js"></script>
<script defer src="modules/ui/routes-editor.js?v=1.89.04"></script>
<script defer src="modules/ui/ice-editor.js"></script>
<script defer src="modules/ui/ice-editor.js?v=1.89.08"></script>
<script defer src="modules/ui/lakes-editor.js?v=1.87.10"></script>
<script defer src="modules/ui/coastline-editor.js"></script>
<script defer src="modules/ui/labels-editor.js"></script>

View file

@ -67,11 +67,11 @@ function editIce() {
function addIcebergOnClick() {
const [x, y] = d3.mouse(this);
const i = findGridCell(x, y, grid);
const c = grid.points[i];
const s = +document.getElementById("iceSize").value;
const [cx, cy] = grid.points[i];
const size = +document.getElementById("iceSize")?.value || 1;
const points = getGridPolygon(i).map(p => [(p[0] + (c[0] - p[0]) / s) | 0, (p[1] + (c[1] - p[1]) / s) | 0]);
const iceberg = ice.append("polygon").attr("points", points).attr("cell", i).attr("size", s);
const points = getGridPolygon(i).map(([x, y]) => [rn(lerp(cx, x, size), 2), rn(lerp(cy, y, size), 2)]);
const iceberg = ice.append("polygon").attr("points", points).attr("cell", i).attr("size", size);
iceberg.call(d3.drag().on("drag", dragElement));
if (d3.event.shiftKey === false) toggleAdd();
}

View file

@ -671,11 +671,10 @@ function toggleIce(event) {
}
function drawIce() {
const cells = grid.cells,
vertices = grid.vertices,
n = cells.i.length,
temp = cells.temp,
h = cells.h;
const {cells, vertices} = grid;
const {temp, h} = cells;
const n = cells.i.length;
const used = new Uint8Array(cells.i.length);
Math.random = aleaPRNG(seed);
@ -700,23 +699,22 @@ function drawIce() {
continue;
}
const tNormalized = normalize(t, -8, 2);
const randomFactor = t > -5 ? 0.4 + rand() * 1.2 : 1;
// mildly cold: iceberd
if (P(normalize(t, -7, 2.5))) continue; // t[-5; 2] cold: skip some cells
if (P(tNormalized ** 0.5 * randomFactor)) continue; // cold: skip some cells
if (grid.features[cells.f[i]].type === "lake") continue; // lake: no icebers
let size = (6.5 + t) / 10; // iceberg size: 0 = full size, 1 = zero size
if (cells.t[i] === -1) size *= 1.3; // coasline: smaller icebers
size = Math.min(size * (0.4 + rand() * 1.2), 0.95); // randomize iceberg size
resizePolygon(i, size);
let size = 1 - tNormalized; // iceberg size: 0 = zero size, 1 = full size
if (cells.t[i] === -1) size /= 1.3; // coasline: smaller icebers
resizePolygon(i, minmax(rn(size * randomFactor, 2), 0.08, 1));
}
function resizePolygon(i, s) {
const c = grid.points[i];
const points = getGridPolygon(i).map(p => [(p[0] + (c[0] - p[0]) * s) | 0, (p[1] + (c[1] - p[1]) * s) | 0]);
ice
.append("polygon")
.attr("points", points)
.attr("cell", i)
.attr("size", rn(1 - s, 2));
function resizePolygon(i, size) {
const [cx, cy] = grid.points[i];
const points = getGridPolygon(i).map(([x, y]) => [rn(lerp(cx, x, size), 2), rn(lerp(cy, y, size), 2)]);
ice.append("polygon").attr("points", points).attr("cell", i).attr("size", size);
}
// connect vertices to chain

View file

@ -20,3 +20,7 @@ function lim(v) {
function normalize(val, min, max) {
return minmax((val - min) / (max - min), 0, 1);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}

View file

@ -1,7 +1,7 @@
"use strict";
// version and caching control
const version = "1.89.07"; // generator version, update each time
const version = "1.89.08"; // generator version, update each time
{
document.title += " v" + version;