canvas = {
const height = 600;
const context = DOM.context2d(width, height);
const radius = Math.min(width, height) / 2 - 2;
const P = polygon(n, radius);
const a = p * -Math.PI * (1 / 2 - 1 / n);
context.translate(width / 2, height / 2);
context.beginPath();
context.moveTo(...P[0]);
for (let i = 1; i < n; ++i) {
context.lineTo(...P[i]);
}
context.closePath();
for (let i = n - 1; i >= 0; --i) {
const [p0, p1] = lineRotate(P[i], P[(i + 1) % n], a);
const [p2, p3] = lineRotate(P[(i + 1) % n], P[(i + 2) % n], a);
const p4 = lineLineIntersect(p0, p1, p2, p3);
if (i === n - 1) context.moveTo(...p4);
else context.lineTo(...p4);
}
context.closePath();
context.fillStyle = "#ddd";
context.fill();
context.lineWidth = 1.5;
context.stroke();
context.beginPath();
for (let i = 0; i < n; ++i) {
const [p0, p1] = lineRotate(P[i], P[(i + 1) % n], a);
const [p2, p3] = lineRotate(P[(i + 1) % n], P[(i + 2) % n], a);
context.moveTo(...p2);
context.lineTo(...lineLineIntersect(p0, p1, p2, p3));
}
context.lineWidth = 1;
context.strokeStyle = "#555";
context.stroke();
yield context.canvas;
}