{const svg = d3.create("svg")
.attr("width", 256)
.attr("height", 256);
const triangleData1 = [];
const triangleData2 = [];
const e = 3;
const step = 18;
const d = step/2;
for (let x = step; x <= 256; x += step) {
for (let y = step; y <= 256; y += step) {
triangleData1.push({
points: [
[x, y - d + e],
[x + e - d, y + d - e],
[x - e + d, y + d - e]
],
borderColor: "blue",
fillColor: "yellow"
});
}
}
for (let x = step; x <= 256; x += step) {
for (let y = step; y <= 256; y += step) {
triangleData2.push({
points: [
[x - step / 2, y + d - e],
[x + e - step / 2 - d, y - d + e],
[x - e - step / 2 + d, y - d + e]
],
borderColor: "red",
fillColor: "white"
});
}
}
const allTriangleData = triangleData1.concat(triangleData2);
svg.selectAll("polygon")
.data(allTriangleData)
.enter()
.append("polygon")
.attr("points", d => d.points.map(p => p.join(",")).join(" "))
.attr("fill", d => d.fillColor)
.attr("stroke", d => d.borderColor)
.attr("stroke-width", 1.2);
return svg.node();
}