Skip to content

Commit f061384

Browse files
committed
add regular polygon implementation
1 parent 506788a commit f061384

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

blob.svg

Lines changed: 20 additions & 0 deletions
Loading

svg.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const size = 600;
2+
const count = 8;
3+
const color = "grey";
4+
5+
const angle = 2 * Math.PI / count;
6+
const distance = size / 3;
7+
8+
const points: {x: number, y: number}[] = [];
9+
for (let i = 0; i < count; i += 1) {
10+
points.push({
11+
x: Math.sin(i * angle) * distance,
12+
y: Math.cos(i * angle) * distance,
13+
});
14+
}
15+
16+
const paths = points.map<string>((point, i) => {
17+
if (i === 0) {
18+
return `M${point.x},${point.y}`;
19+
}
20+
return `L${point.x},${point.y}`;
21+
});
22+
paths.push("Z");
23+
24+
console.log(`
25+
<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg">
26+
<g transform="translate(${size / 2}, ${size / 2})">
27+
<path
28+
stroke="none"
29+
stroke-width="0"
30+
fill="${color}"
31+
d="${paths.join("\n")}"
32+
/>
33+
</g>
34+
</svg>
35+
`);
36+
37+
// const r = (a, b) => Math.min(a, b) + (Math.abs(a - b) * Math.random());

0 commit comments

Comments
 (0)