Clean up a bit
This commit is contained in:
parent
6714c5f6f7
commit
e315cdeddc
@ -134,7 +134,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<svg viewBox="-200 -150 400 300" xmlns="http://www.w3.org/2000/svg">
|
<svg viewBox="-300 -400 600 800" xmlns="http://www.w3.org/2000/svg">
|
||||||
<!-- <svg viewBox="-30 -20 60 40" xmlns="http://www.w3.org/2000/svg"> -->
|
<!-- <svg viewBox="-30 -20 60 40" xmlns="http://www.w3.org/2000/svg"> -->
|
||||||
<defs>
|
<defs>
|
||||||
<polygon id="hex" points="0,10 8.66,5 8.66,-5 0,-10 -8.66,-5 -8.66,5" />
|
<polygon id="hex" points="0,10 8.66,5 8.66,-5 0,-10 -8.66,-5 -8.66,5" />
|
||||||
|
@ -62,7 +62,7 @@ function generateRadialCoords(l, { q, r, s }, radius) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } = {}, { q = 0, r = 0, s = 0 } = {}) {
|
function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } = {}, { q = 0, r = 0, s = 0 } = {}) {
|
||||||
const list = new Set();
|
const list = new Map();
|
||||||
|
|
||||||
for (let row = 0; row < rows; row++) {
|
for (let row = 0; row < rows; row++) {
|
||||||
const alternating = row % 2;
|
const alternating = row % 2;
|
||||||
@ -77,7 +77,7 @@ function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } =
|
|||||||
ds = ds + alternating;
|
ds = ds + alternating;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.add(toKey(q + dq, r + dr, s + ds));
|
list.set(toKey(q + dq, r + dr, s + ds), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!equal) {
|
if (!equal) {
|
||||||
@ -90,7 +90,7 @@ function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } =
|
|||||||
ds = ds + alternating;
|
ds = ds + alternating;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.add(toKey(q + dq, r + dr, s + ds));
|
list.set(toKey(q + dq, r + dr, s + ds), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,35 +275,40 @@ bld1.appendChild(bld1elv1);
|
|||||||
bld1hexes.forEach(coords => grid.delete(coords))
|
bld1hexes.forEach(coords => grid.delete(coords))
|
||||||
bld2hexes.forEach(list => list.forEach(coords => grid.delete(coords)));
|
bld2hexes.forEach(list => list.forEach(coords => grid.delete(coords)));
|
||||||
|
|
||||||
// drawHexes(elevation1, grid);
|
|
||||||
|
|
||||||
function generateRadialCoords2(l, { q, r, s }) {
|
function generateRadialCoords2(l, { q, r, s }) {
|
||||||
const origin = toKey(q, r, s);
|
const origin = toKey(q, r, s);
|
||||||
const list = new Map(l);
|
const list = new Map(l);
|
||||||
let level = 0;
|
|
||||||
|
|
||||||
list.set(origin, level);
|
list.set(origin, 0);
|
||||||
let queue = [origin];
|
let queue = [origin];
|
||||||
|
|
||||||
const top = 5;
|
const top = 26;
|
||||||
const bottom = 5;
|
const bottom = 27;
|
||||||
|
const left = 17;
|
||||||
const left = 1;
|
const right = 17;
|
||||||
const right = 1;
|
const offset = 'right';
|
||||||
|
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
level++;
|
|
||||||
const v = queue.shift();
|
const v = queue.shift();
|
||||||
|
|
||||||
getNeighbors(v).forEach(w => {
|
getNeighbors(v).forEach(w => {
|
||||||
const [wq, wr, ws] = w.split(',').map(n => +n);
|
const [wq, wr, ws] = w.split(',').map(n => +n);
|
||||||
const rDist = Math.abs(wr - r);
|
const rDist = Math.abs(wr - r);
|
||||||
const dr = (rDist + rDist % 2) / 2;
|
const dr = (rDist + rDist % 2) / 2;
|
||||||
|
|
||||||
|
let dLeft = left;
|
||||||
|
let dRight = right;
|
||||||
|
|
||||||
|
if (offset === 'left')
|
||||||
|
dRight -= rDist % 2;
|
||||||
|
else if (offset === 'right')
|
||||||
|
dLeft -= rDist % 2;
|
||||||
|
|
||||||
if ([
|
if ([
|
||||||
!list.has(w),
|
!list.has(w),
|
||||||
wr < bottom + r && wr > -top + r,
|
wr < bottom + r && wr > -top + r,
|
||||||
wq > -right + q - dr && wq < left + q + dr,
|
wq > -dRight + q - dr && wq < dLeft + q + dr,
|
||||||
ws > -left + s - dr && ws < right + s + dr,
|
ws > -dLeft + s - dr && ws < dRight + s + dr,
|
||||||
].every(v => v)) {
|
].every(v => v)) {
|
||||||
list.set(w, dr);
|
list.set(w, dr);
|
||||||
queue.push(w);
|
queue.push(w);
|
||||||
@ -335,7 +340,8 @@ const list = generateRadialCoords2(new Map(), { q: 0, r: 0, s: 0 });
|
|||||||
// q [-2, -8]
|
// q [-2, -8]
|
||||||
// s [-2, 4]
|
// s [-2, 4]
|
||||||
|
|
||||||
drawHexes(elevation2, generateRadialCoords(new Map(), { q: 0, r: 0, s: 0 }, 10));
|
// drawHexes(elevation2, generateRadialCoords(new Map(), { q: 0, r: 0, s: 0 }, 10));
|
||||||
|
drawHexes(elevation2, grid);
|
||||||
drawHexes(elevation1, list);
|
drawHexes(elevation1, list);
|
||||||
|
|
||||||
const defs = svg.querySelector('defs');
|
const defs = svg.querySelector('defs');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user