Skip to content

Commit c667054

Browse files
committed
start adding public api
1 parent e85ee24 commit c667054

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

public/gen.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {genBlob} from "../internal/blobs";
2+
import {rand} from "../internal/rand";
3+
import {Shape} from "../internal/types";
4+
5+
export interface GenOptions {
6+
seed: string | number;
7+
extraPoints: number;
8+
randomness: number;
9+
}
10+
11+
export interface Blob {
12+
shape: Shape;
13+
}
14+
15+
export const gen = (opt: GenOptions) => {
16+
const rgen = rand(String(opt.seed));
17+
18+
// Scale of random movement increases as randomness approaches infinity.
19+
// randomness = 0 -> rangeStart = 1
20+
// randomness = 2 -> rangeStart = 0.8333
21+
// randomness = 5 -> rangeStart = 0.6667
22+
// randomness = 10 -> rangeStart = 0.5
23+
// randomness = 20 -> rangeStart = 0.3333
24+
// randomness = 50 -> rangeStart = 0.1667
25+
// randomness = 100 -> rangeStart = 0.0909
26+
const rangeStart = 1 / (1 + Math.abs(opt.randomness) / 10);
27+
28+
return genBlob(3 + Math.abs(opt.extraPoints), () => rangeStart + rgen() * (1 - rangeStart));
29+
};

0 commit comments

Comments
 (0)