Canvas path hole (counter shape) #419
-
I was trying to create a shape with a hole. With Canvas API, I draw the main shape clockwise, and the counter shape counter-cw. If anyone has a tip, I'd appreciate it. // prettier-ignore
const pts: [number, number][] = [
[100, 100], [500, 100], [500, 500], [100, 500]
];
// prettier-ignore
const hole: [number, number][] = [
[300, 200], [200, 400], [400, 400]
];
// canvas api
pts.forEach((pt, i) => (i === 0 ? ctx.moveTo(...pt) : ctx.lineTo(...pt)));
hole.forEach((pt, i) => (i === 0 ? ctx.moveTo(...pt) : ctx.lineTo(...pt)));
ctx.fillStyle = "yellow";
ctx.fill();
// thi.ng
const path = new PathBuilder({ fill: "white", translate: [200, 200] });
pts.forEach((pt, i) => (i === 0 ? path.moveTo(pt) : path.lineTo(pt)));
hole.forEach((pt, i) => (i === 0 ? path.moveTo(pt) : path.lineTo(pt)));
draw(ctx, path.current()); |
Beta Was this translation helpful? Give feedback.
Answered by
postspectacular
Oct 21, 2023
Replies: 1 comment 1 reply
-
Hey @cdaein - sorry, just saw your question now! Alas, holes are currently not directly supported, neither in paths nor in polygons. For various reasons, only simple boundary representations for now... |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cdaein
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @cdaein - sorry, just saw your question now! Alas, holes are currently not directly supported, neither in paths nor in polygons. For various reasons, only simple boundary representations for now...