{
const svg = d3.create("svg").attr("height", height).attr("width", width);
let cx = width / 2;
let cy = height / 2;
svg
.append("circle")
.attr("cx", cx)
.attr("cy", cy)
.attr("r", size / 2)
.attr("fill", "black");
for (let i = 0; i < 4; i++) {
let giuntoX = size / 2 + 20 + i * 20 + Math.random() * 10;
let giuntoY = 0 + i * 10;
let points = [
[cx, cy],
[cx + giuntoX, cy - giuntoY],
[cx + giuntoX, height]
];
svg
.append("path")
.attr("d", d3.line()(points))
.attr("fill", "none")
.attr("stroke", "black");
svg
.append("path")
.attr("transform", `translate(${cx + giuntoX},${height})`)
.attr(
"d",
d3.arc()({
innerRadius: 0,
outerRadius: Math.random() * 5 + 5,
startAngle: -Math.PI / 2,
endAngle: Math.PI / 2
})
);
}
for (let i = 0; i < 4; i++) {
let giuntoX = size / 2 + 20 + i * 20 + Math.random() * 10;
let giuntoY = 0 + i * 10;
let points = [
[cx, cy],
[cx - giuntoX, cy - giuntoY],
[cx - giuntoX, height]
];
svg
.append("path")
.attr("d", d3.line()(points))
.attr("fill", "none")
.attr("stroke", "black");
svg
.append("path")
.attr("transform", `translate(${cx - giuntoX},${height})`)
.attr(
"d",
d3.arc()({
innerRadius: 0,
outerRadius: Math.random() * 5 + 5,
startAngle: -Math.PI / 2,
endAngle: Math.PI / 2
})
);
}
for (let i = 0; i < eyes; i++) {
let angle = Math.random() * Math.PI - Math.PI;
let distance = Math.random() * 0.3 + 0.5;
let eyeSize = Math.random() * 5 + 5;
let xPos = width / 2 + (Math.cos(angle) * size * distance) / 2;
let yPos = height / 2 + (Math.sin(angle) * size * distance) / 2;
let eye = svg.append("g");
eye
.append("circle")
.attr("cx", xPos)
.attr("cy", yPos)
.attr("r", eyeSize)
.attr("fill", "white");
eye
.append("circle")
.attr("cx", xPos)
.attr("cy", yPos)
.attr("r", eyeSize / 3)
.attr("fill", "red");
}
return svg.node();
}