@@ -41,47 +41,47 @@ export interface BlobOptions extends PathOptions {
4141}
4242
4343// Generates an svg document string containing a randomized blob.
44- const blobs = ( opt : BlobOptions ) : string => {
45- return blobs . editable ( opt ) . render ( ) ;
44+ const blobs = ( options : BlobOptions ) : string => {
45+ return blobs . editable ( options ) . render ( ) ;
4646} ;
4747
4848// Generates a randomized blob as an editable data structure which can be rendered to an svg document.
49- blobs . editable = ( opt : BlobOptions ) : XmlElement => {
50- if ( ! opt ) {
49+ blobs . editable = ( options : BlobOptions ) : XmlElement => {
50+ if ( ! options ) {
5151 throw new Error ( "no options specified" ) ;
5252 }
5353
5454 // Random number generator.
55- const rgen = rand ( opt . seed || String ( Date . now ( ) ) ) ;
55+ const rgen = rand ( options . seed || String ( Date . now ( ) ) ) ;
5656
57- if ( ! opt . size ) {
57+ if ( ! options . size ) {
5858 throw new Error ( "no size specified" ) ;
5959 }
6060
61- if ( ! opt . stroke && ! opt . color ) {
61+ if ( ! options . stroke && ! options . color ) {
6262 throw new Error ( "no color or stroke specified" ) ;
6363 }
6464
65- if ( opt . complexity <= 0 || opt . complexity > 1 ) {
65+ if ( options . complexity <= 0 || options . complexity > 1 ) {
6666 throw new Error ( "complexity out of range ]0,1]" ) ;
6767 }
6868
69- if ( opt . contrast < 0 || opt . contrast > 1 ) {
69+ if ( options . contrast < 0 || options . contrast > 1 ) {
7070 throw new Error ( "contrast out of range [0,1]" ) ;
7171 }
7272
73- const count = 3 + Math . floor ( 14 * opt . complexity ) ;
74- const offset = ( ) : number => ( 1 - 0.8 * opt . contrast * rgen ( ) ) / Math . E ;
73+ const count = 3 + Math . floor ( 14 * options . complexity ) ;
74+ const offset = ( ) : number => ( 1 - 0.8 * options . contrast * rgen ( ) ) / Math . E ;
7575
7676 const points = mapPoints ( genBlob ( count , offset ) , ( { curr} ) => {
7777 // Scale.
78- curr . x *= opt . size ;
79- curr . y *= opt . size ;
80- curr . handleIn . length *= opt . size ;
81- curr . handleOut . length *= opt . size ;
78+ curr . x *= options . size ;
79+ curr . y *= options . size ;
80+ curr . handleIn . length *= options . size ;
81+ curr . handleOut . length *= options . size ;
8282
8383 // Flip around x-axis.
84- curr . y = opt . size - curr . y ;
84+ curr . y = options . size - curr . y ;
8585 curr . handleIn . angle *= - 1 ;
8686 curr . handleOut . angle *= - 1 ;
8787
@@ -90,13 +90,13 @@ blobs.editable = (opt: BlobOptions): XmlElement => {
9090
9191 return renderEditable ( points , {
9292 closed : true ,
93- width : opt . size ,
94- height : opt . size ,
95- fill : opt . color ,
96- transform : `rotate(${ rgen ( ) * ( 360 / count ) } ,${ opt . size / 2 } ,${ opt . size / 2 } )` ,
97- stroke : opt . stroke && opt . stroke . color ,
98- strokeWidth : opt . stroke && opt . stroke . width ,
99- guides : opt . guides ,
93+ width : options . size ,
94+ height : options . size ,
95+ fill : options . color ,
96+ transform : `rotate(${ rgen ( ) * ( 360 / count ) } ,${ options . size / 2 } ,${ options . size / 2 } )` ,
97+ stroke : options . stroke && options . stroke . color ,
98+ strokeWidth : options . stroke && options . stroke . width ,
99+ guides : options . guides ,
100100 } ) ;
101101} ;
102102
0 commit comments