{
const columnas = 32;
const filas = 16;
const base = 18;
const altura = 18;
const padding = 2;
const width = columnas * (base + padding);
const height = filas * (altura + padding);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const puntos = Array.from({ length: filas }, (_, y) =>
Array.from({ length: columnas }, (_, x) => {
const cx = x * (base + padding) + base / 2;
const cy = y * (altura + padding) + altura / 2;
const haciaArriba = x % 2 === 0;
const vertices = haciaArriba
? [
[cx, cy - altura / 2],
[cx - base / 2, cy + altura / 2],
[cx + base / 2, cy + altura / 2]
]
: [
[cx, cy + altura / 2],
[cx - base / 2, cy - altura / 2],
[cx + base / 2, cy - altura / 2]
];
const fill = haciaArriba ? "yellow" : "white";
const stroke = haciaArriba ? "blue" : "red";
return { vertices, fill, stroke };
})
).flat();
puntos.forEach(({ vertices, fill, stroke }) => {
svg.append("polygon")
.attr("points", vertices.map(p => p.join(",")).join(" "))
.attr("fill", fill)
.attr("stroke", stroke);
});
return svg.node();
}