Methods

(static) clamp(v, min, max) → {number}

Clamp a float to be between [min, max).

Parameters:
NameTypeDescription
vnumber

value to clamp between min & max

minnumber

min value

maxnumber

max value

Returns:

a float between min/max

Type: 
number

(static) degToRad(degrees) → {number}

Convert from degrees to radians

Parameters:
NameTypeDescription
degreesnumber

a value in degrees: in [0, 360)

Returns:

the value as radians: in [0, 2PI)

Type: 
number

(static) headingToRad(heading) → {number}

Convert from heading to radians

Parameters:
NameTypeDescription
headingnumber

a value in degrees: in [0, 360)

Returns:

a value in radians: in [0, 2PI)

Type: 
number

(static) mod(v, n) → {number}

A true modulus function, differing from the % remainder operation.

Parameters:
NameTypeDescription
vnumber

The value to calculate the modulus of

nnumber

The number relative to which the modulus is calculated.

Returns:

The value of v mod n

Type: 
number

(static) oneOf(An) → {any}

Return random item from an array

Parameters:
NameTypeDescription
AnArray

array to choose from

Returns:

The chosen item

Type: 
any

(static) pause(msopt) → {Promise}

Return promise for pause of ms. Use: await pause(ms)

Parameters:
NameTypeAttributesDefaultDescription
msnumber<optional>
1000

Number of ms to pause

Returns:

A promise to wait this number of ms

Type: 
Promise

(static) precision(num, digitsopt) → {number}

Round a number to be of a given decimal precision. If the number is an array, round each item in the array

Parameters:
NameTypeAttributesDefaultDescription
numnumber | Array

The number to convert/shorten

digitsnumber<optional>
4

The number of decimal digits

Returns:

The resulting number

Type: 
number

(static) radToDeg(radians) → {number}

Convert from radians to degrees

Parameters:
NameTypeDescription
radiansnumber

a value in radians: in [0, 2PI)

Returns:

the value as degrees: in [0, 360)

Type: 
number

(static) radToHeading(radians) → {number}

Convert from radians to heading

Heading is 0-up (y-axis), clockwise angle measured in degrees. Radians is euclidean: 0-right (x-axis), counterclockwise in radians

Parameters:
NameTypeDescription
radiansnumber

a value in radians: in [0, 2PI)

Returns:

a value in degrees: in [0, 360)

Type: 
number

(static) randomCentered(r) → {number}

Return a random float centered around r, in [-r/2, r/2)

Parameters:
NameTypeDescription
rnumber

The center float

Returns:

a float in [-r/2, r/2)

Type: 
number

(static) randomFloat(max) → {number}

Returns a random float in [0, max)

Parameters:
NameTypeDescription
maxnumber

The max float to return

Returns:

a float in [0, max)

Type: 
number

(static) randomFloat2(min, max) → {number}

Returns a random float in [min, max)

Parameters:
NameTypeDescription
minnumber

The min float to return

maxnumber

The max float to return

Returns:

a float in [min, max)

Type: 
number

(static) randomInt(max) → {number}

Returns ramdp, int in [0, max), equal or grater than 0, less than max

Parameters:
NameTypeDescription
maxnumber

The max integer to return

Returns:

an integer in [0, max)

Type: 
number

(static) randomInt2(min, max) → {number}

Returns an int in [min, max), equal or grater than min, less than max

Parameters:
NameTypeDescription
minnumber

The min integer to return

maxnumber

The max integer to return

Returns:

an integer in [min, max)

Type: 
number

(static) randomSeed(seedopt)

Install a seeded random generator as Math.random Uses an optimized version of the Park-Miller PRNG.

Math.random will return a sequence of "random" numbers in a known sequence. Useful for testing to see if the same results occur in multiple runs of a model with the same parameters.

Parameters:
NameTypeAttributesDefaultDescription
seednumber<optional>
123456

(static) repeat(n, f, aopt) → {Array}

Repeats the function f(i, a) i in 0, n-1. a is an optional array, default a new empty Array returns a, only needed if f() places data in a

Parameters:
NameTypeAttributesDefaultDescription
nnumber

An integer number of times to run f()

ffunction

The function called.

aArray<optional>
[]

An optional array for use by f()

Returns:

The result of calling f() n times

Type: 
Array

(static) sampleModel(model) → {Object}

Return an object with samples of the models components. Useful for testing Models without needing a View, just data.

Parameters:
NameTypeDescription
modelModel

A model to sample

Returns:

An object with all the samples

Type: 
Object

(static) subtractHeadings(head1, head0) → {number}

Subtract two headings, returning the smaller difference.

Computes the difference between the given headings, that is, the number of degrees in the smallest angle by which heading2 could be rotated to produce heading1 See NetLogo's subtract-headings for explanation

Parameters:
NameTypeDescription
head1number

The first heading in degrees

head0number

The second heading in degrees

Returns:

The smallest andle from head0 to head1

Type: 
number

(static) timeoutLoop(fcn, stepsopt, msopt)

Use pause for an animation loop. Calls the fcn each step Stops after steps calls, negative means run forever

Parameters:
NameTypeAttributesDefaultDescription
fcnfunction

The function to be called.

stepsnumber<optional>
-1

How many times, -1 means forever

msnumber<optional>
0

Number of ms between calls.