mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 02:21:24 +01:00
refactor: geColor
This commit is contained in:
parent
289620615f
commit
849581af50
1 changed files with 8 additions and 5 deletions
|
|
@ -485,10 +485,14 @@ function editHeightmap(options) {
|
||||||
updateHistory();
|
updateHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getColor(value, scheme = getColorScheme()) {
|
||||||
|
return scheme(1 - (value < 20 ? value - 5 : value) / 100);
|
||||||
|
}
|
||||||
|
|
||||||
// draw or update heightmap
|
// draw or update heightmap
|
||||||
function mockHeightmap() {
|
function mockHeightmap() {
|
||||||
const data = renderOcean.checked ? grid.cells.i : grid.cells.i.filter(i => grid.cells.h[i] >= 20);
|
const data = renderOcean.checked ? grid.cells.i : grid.cells.i.filter(i => grid.cells.h[i] >= 20);
|
||||||
const scheme = getColorScheme();
|
|
||||||
viewbox
|
viewbox
|
||||||
.select("#heights")
|
.select("#heights")
|
||||||
.selectAll("polygon")
|
.selectAll("polygon")
|
||||||
|
|
@ -496,13 +500,12 @@ function editHeightmap(options) {
|
||||||
.join("polygon")
|
.join("polygon")
|
||||||
.attr("points", d => getGridPolygon(d))
|
.attr("points", d => getGridPolygon(d))
|
||||||
.attr("id", d => "cell" + d)
|
.attr("id", d => "cell" + d)
|
||||||
.attr("fill", d => getColor(grid.cells.h[d], scheme));
|
.attr("fill", d => getColor(grid.cells.h[d]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw or update heightmap for a selection of cells
|
// draw or update heightmap for a selection of cells
|
||||||
function mockHeightmapSelection(selection) {
|
function mockHeightmapSelection(selection) {
|
||||||
const ocean = renderOcean.checked;
|
const ocean = renderOcean.checked;
|
||||||
const scheme = getColorScheme();
|
|
||||||
|
|
||||||
selection.forEach(function (i) {
|
selection.forEach(function (i) {
|
||||||
let cell = viewbox.select("#heights").select("#cell" + i);
|
let cell = viewbox.select("#heights").select("#cell" + i);
|
||||||
|
|
@ -514,7 +517,7 @@ function editHeightmap(options) {
|
||||||
.append("polygon")
|
.append("polygon")
|
||||||
.attr("points", getGridPolygon(i))
|
.attr("points", getGridPolygon(i))
|
||||||
.attr("id", "cell" + i);
|
.attr("id", "cell" + i);
|
||||||
cell.attr("fill", getColor(grid.cells.h[i], scheme));
|
cell.attr("fill", getColor(grid.cells.h[i]));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1345,7 +1348,7 @@ function editHeightmap(options) {
|
||||||
return lum | 0; // land
|
return lum | 0; // land
|
||||||
};
|
};
|
||||||
|
|
||||||
const scheme = d3.range(101).map(i => getColor(i, color()));
|
const scheme = d3.range(101).map(i => getColor(i));
|
||||||
const hues = scheme.map(rgb => d3.hsl(rgb).h | 0);
|
const hues = scheme.map(rgb => d3.hsl(rgb).h | 0);
|
||||||
const getHeightByScheme = function (color) {
|
const getHeightByScheme = function (color) {
|
||||||
let height = scheme.indexOf(color);
|
let height = scheme.indexOf(color);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue