Skip to content

Commit 78aa4cc

Browse files
committed
add randomness to point distance
1 parent 3846af8 commit 78aa4cc

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

blob.svg

Lines changed: 9 additions & 9 deletions
Loading

svg.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const rand = (a, b) => Math.min(a, b) + (Math.abs(a - b) * Math.random());
22

33
const size = 600;
4-
const count = 8;
4+
const count = 5;
5+
const randomness = 0.6;
56
const color = "grey";
67

78
const angle = 2 * Math.PI/count;
@@ -10,9 +11,10 @@ const ctrlDistance = distance * 4/3 * Math.tan(angle/4);
1011

1112
const points: {x: number, y: number}[] = [];
1213
for (let i = 0; i < count; i++) {
14+
const randomizedDistance = rand(distance * randomness, distance);
1315
points.push({
14-
x: Math.sin(i*angle) * distance,
15-
y: Math.cos(i*angle) * distance,
16+
x: Math.sin(i*angle) * randomizedDistance,
17+
y: Math.cos(i*angle) * randomizedDistance,
1618
});
1719
}
1820

@@ -38,10 +40,11 @@ for (let i = 0; i <= count; i++) {
3840
continue;
3941
}
4042

41-
//
43+
// Add cubic bezier coordinates using the computed control positions.
4244
paths.push(`C${control.x2},${control.y2},${control.x1},${control.y1},${point.x},${point.y}`);
4345

4446
}
47+
4548
// Close the path.
4649
paths.push("Z");
4750

@@ -64,9 +67,9 @@ console.log(`
6467
return `<circle cx="${x}" cy="${y}" r="2" fill="${i === 0 ? "black" : "blue"}" />`;
6568
}).join("")}
6669
<path
67-
stroke="none"
68-
stroke-width="0"
69-
fill="${color}"
70+
stroke="cyan"
71+
stroke-width="1"
72+
fill="${"none" || color}"
7073
d="${paths.join("")}"
7174
/>
7275
</g>

0 commit comments

Comments
 (0)