Methods

(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) 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.

(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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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:

N results of calling f() n times

Type: 
Array

(static) oneOf(An) → {any}

Return random item from an array

Parameters:
NameTypeDescription
AnArray

array to choose from

Returns:

The chosen item

Type: 
any

(static) imagePromise(url) → {Promise}

Return a Promise for getting an image. See https://deno.land/x/skia_canvas/mod.ts?s=Image for Image in deno

use: imagePromise('./path/to/img').then(img => imageFcn(img)) or: await imagePromise('./path/to/img')

Parameters:
NameTypeDescription
urlstring

URL for path to image

Returns:

A promise resolving to the image

Type: 
Promise

(static) createCanvas(width, height, preferDOMopt) → {Canvas}

Create a blank 2D canvas of a given width/height.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber

The canvas height in pixels

heightnumber

The canvas width in pixels

preferDOMboolean<optional>
false

If false, return "Offscreen" canvas

Returns:

The resulting Canvas object

Type: 
Canvas

(static) createCtx(width, height, offscreenopt) → {Context2D}

As above, but returing the 2D context object instead of the canvas. Note ctx.canvas is the canvas for the ctx, and can be use as an image.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber

The canvas height in pixels

heightnumber

The canvas width in pixels

offscreenboolean<optional>
offscreenOK()

If true, return "Offscreen" canvas

Returns:

The resulting Canvas's 2D context

Type: 
Context2D

(static) setCtxImage(ctx, img)

Fill this context with the given image, resizing it to img size if needed.

Parameters:
NameTypeDescription
ctxContext2D

a canvas 2D context

imgImage

the Image to install in this ctx

(static) toWindow(obj)

Merge a module's obj key/val pairs into to the global/window namespace. Primary use is to make console logging easier when debugging modules.

Parameters:
NameTypeDescription
objObject

Object who's key/val pairs will be installed in window.