Methods
(static) pause(msopt) → {Promise}
Return promise for pause of ms. Use: await pause(ms)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ms | number | <optional> | 1000 | Number of ms to pause |
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
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fcn | function | The function to be called. | ||
steps | number | <optional> | -1 | How many times, -1 means forever |
ms | number | <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
Name | Type | Description |
---|---|---|
max | number | The max integer to return |
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
Name | Type | Description |
---|---|---|
min | number | The min integer to return |
max | number | The max integer to return |
an integer in [min, max)
- Type:
- number
(static) randomFloat(max) → {number}
Returns a random float in [0, max)
Name | Type | Description |
---|---|---|
max | number | The max float to return |
a float in [0, max)
- Type:
- number
(static) randomFloat2(min, max) → {number}
Returns a random float in [min, max)
Name | Type | Description |
---|---|---|
min | number | The min float to return |
max | number | The max float to return |
a float in [min, max)
- Type:
- number
(static) randomCentered(r) → {number}
Return a random float centered around r, in [-r/2, r/2)
Name | Type | Description |
---|---|---|
r | number | The center float |
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.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
seed | number | <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
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
num | number | | The number to convert/shorten | ||
digits | number | <optional> | 4 | The number of decimal digits |
The resulting number
- Type:
- number
(static) mod(v, n) → {number}
A true modulus function, differing from the % remainder operation.
Name | Type | Description |
---|---|---|
v | number | The value to calculate the modulus of |
n | number | The number relative to which the modulus is calculated. |
The value of v mod n
- Type:
- number
(static) clamp(v, min, max) → {number}
Clamp a float to be between [min, max).
Name | Type | Description |
---|---|---|
v | number | value to clamp between min & max |
min | number | min value |
max | number | max value |
a float between min/max
- Type:
- number
(static) degToRad(degrees) → {number}
Convert from degrees to radians
Name | Type | Description |
---|---|---|
degrees | number | a value in degrees: in [0, 360) |
the value as radians: in [0, 2PI)
- Type:
- number
(static) radToDeg(radians) → {number}
Convert from radians to degrees
Name | Type | Description |
---|---|---|
radians | number | a value in radians: in [0, 2PI) |
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
Name | Type | Description |
---|---|---|
radians | number | a value in radians: in [0, 2PI) |
a value in degrees: in [0, 360)
- Type:
- number
(static) headingToRad(heading) → {number}
Convert from heading to radians
Name | Type | Description |
---|---|---|
heading | number | a value in degrees: in [0, 360) |
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
Name | Type | Description |
---|---|---|
head1 | number | The first heading in degrees |
head0 | number | The second heading in degrees |
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.
Name | Type | Description |
---|---|---|
model | Model | A model to sample |
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
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n | number | An integer number of times to run f() | ||
f | function | The function called. | ||
a | Array | <optional> | [] | An optional array for use by f() |
N results of calling f() n times
- Type:
- Array
(static) oneOf(An) → {any}
Return random item from an array
Name | Type | Description |
---|---|---|
An | Array | array to choose from |
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')
Name | Type | Description |
---|---|---|
url | string | URL for path to image |
A promise resolving to the image
- Type:
- Promise
(static) createCanvas(width, height, preferDOMopt) → {Canvas}
Create a blank 2D canvas of a given width/height.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
width | number | The canvas height in pixels | ||
height | number | The canvas width in pixels | ||
preferDOM | boolean | <optional> | false | If false, return "Offscreen" canvas |
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.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
width | number | The canvas height in pixels | ||
height | number | The canvas width in pixels | ||
offscreen | boolean | <optional> | offscreenOK() | If true, return "Offscreen" canvas |
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.
Name | Type | Description |
---|---|---|
ctx | Context2D | a canvas 2D context |
img | Image | 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.
Name | Type | Description |
---|---|---|
obj | Object | Object who's key/val pairs will be installed in window. |