-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths-hole.ts
47 lines (40 loc) · 1.06 KB
/
paths-hole.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
complexPolygon,
flip,
group,
polygon,
type Polygon,
} from "@thi.ng/geom";
import { draw } from "@thi.ng/hiccup-canvas";
import { Sketch, SketchSettings, ssam } from "ssam";
export const sketch: Sketch<"2d"> = ({ wrap, context: ctx }) => {
const poly1 = polygon([
[100, 150],
[500, 150],
[700, 400],
[500, 700],
[300, 700],
[100, 400],
]);
const poly2 = polygon([
[300, 300],
[350, 300],
[350, 350],
[300, 350],
]);
// NOTE: need casting for flip() return
const combined = complexPolygon(poly1, [flip(poly2) as Polygon]);
wrap.render = ({ width, height }) => {
ctx.fillStyle = `gray`;
ctx.fillRect(0, 0, width, height);
draw(ctx, group({ fill: "blue", translate: [80, 50] }, [combined]));
draw(ctx, group({ stroke: "yellow", weight: 2 }, [poly1, poly2]));
};
};
export const settings: SketchSettings = {
dimensions: [800, 800],
pixelRatio: window.devicePixelRatio,
animate: true,
filename: import.meta.url?.split("/").pop()?.split(".")[0] || undefined,
};
ssam(sketch, settings);