const svg = d3.create("svg")
.attr("width", 256)
.attr("height", 256);
const rows = 8;
const cols = 8;
const triangleSize = 32;
function drawTriangle(x, y, color) {
svg.append("polygon")
.attr("points", `${x},${y} ${x + triangleSize},${y} ${x + triangleSize / 2},${y - triangleSize}`)
.attr("fill", color)
.attr("stroke", "black")
.attr("stroke-width", 1);
}
const colors = ["red", "orange", "yellow", "green", "blue", "purple"];
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const x = col *triangleSize;
const y = row * triangleSize;
const colorIndex = (row + col) % colors.length;
drawTriangle(x, y, colors[colorIndex]);
}
}
return svg.node();