File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments