### agentscript

`0.10.3`
Need help reading this?

## Turtles, Patches, and Links

### Turtle

src/Turtle.js

Class Turtle instances represent the dynamic, behavioral element of modeling. Each turtle knows the patch it is on, and interacts with that and other patches, as well as other turtles. They are also the end points of Links.

You do not call `new Turtle()`, instead class Turtles creates it's Turtle instances. I.e. class Turtles is a factory for all of it's Turtle instances. So don't do this:

new Turtle()
Instance Members
▸ die()
src/Turtle.js

Ask this turtle to "die"

- Removes itself from the Turtles array
- Removes itself from any Turtles breeds
- Removes all my Links if any exist
- Removes me from my Patch list of turtles on it
- Set it's id to -1 to indicate to others it's gone

die()
▸ hatch(num, breed, init)
src/Turtle.js

Factory method: create num new turtles at this turtle's location.

hatch(num: number, breed: AgentSet, init: Function): Array
Parameters
num `(number = `1`)` The number of new turtles to create
breed `(AgentSet = `this.agentSet`)` The type of turtles to create, defaults to my type
init `(Function = `turtle=>{}`)` A function to initialize the new turtles, defaults to no-op
Returns
`Array`: An Array of the new Turtles, generally ignored due to the init function
▸ links
src/Turtle.js

Returns an array of the Links that have this Turtle as one of the end points

links
Returns
`Array`: An AgentList Array of my Links
▸ patch
src/Turtle.js

Return the patch this Turtle is on. Return null if Turtle off-world.

patch
▸ heading
src/Turtle.js

Return this Turtle's heading

heading
▸ heading
src/Turtle.js

Sets this Turtle's heading

heading
Parameters
heading `(any)`
▸ subtractHeading(heading)
src/Turtle.js

Computes the difference between the my heading and the given heading, the smallest angle by which t could be rotated to produce heading.

subtractHeading(heading: Angle): Angle
Parameters
heading `(Angle)` The heading I wish to be roated to.
Returns
`Angle`:
▸ setxy(x, y, z)
src/Turtle.js

Set Turtles x, y position. If z given, override default z of 0.

setxy(x: number, y: number, z: (number | undefined))
Parameters
x `(number)` Turtle's x coord, a Float in patch space
y `(number)` Turtle's Y coord, a Float in patch space
z `((number | undefined) = `undefined`)` Turtle's Z coord if given
▸ handleEdge(x, y, z)
src/Turtle.js

Handle turtle x,y,z if turtle off-world. Uses the Turtle's atEdge property to determine how to manage the Turtle. Defaults to 'wrap', wrapping the x,y,z to the opposite edge.

atEdge can be:

- 'wrap'
- 'bounce'
- 'clamp'
- a function called with the Turtle as it's argument

handleEdge(x: number, y: number, z: (number | undefined))
Parameters
x `(number)` Turtle's x coord
y `(number)` Turtle's y coord
z `((number | undefined) = `undefined`)` Turtle's z coord if not undefined
▸ moveTo(agent)
src/Turtle.js

Place the turtle at the given patch/turtle location

moveTo(agent: (Patch | Turtle))
Parameters
agent `((Patch | Turtle))` A Patch or Turtle who's location is used
▸ forward(d)
src/Turtle.js

Move forward, along the Turtle's heading d units in Patch coordinates

forward(d: number)
Parameters
d `(number)` The distance to move
▸ rotate(angle)
src/Turtle.js

Change Turtle's heading by angle

rotate(angle: number)
Parameters
angle `(number)` The angle to rotate by
▸ right(angle)
src/Turtle.js

Turn Turtle right by angle

right(angle: number)
Parameters
angle `(number)` The angle to rotate by
▸ left(angle)
src/Turtle.js

Turn Turtle left by angle

left(angle: number)
Parameters
angle `(number)` The angle to rotate by
▸ face(agent)
src/Turtle.js

Turn turtle so at to be facing the given Turtle or Patch

face(agent: (Patch | Turtle))
Parameters
agent `((Patch | Turtle))` The agent to face towards
▸ facexy(x, y)
src/Turtle.js

Turn turtle so at to be facing the given x, y patch coordinate

facexy(x: number, y: number)
Parameters
x `(number)` The x coordinate
y `(number)` The y coordinate
▸ patchAhead(distance)
src/Turtle.js

Return the patch ahead of this turtle by distance. Return undefined if the distance puts the patch off-world

patchAhead(distance: number): (Patch | undefined)
Parameters
distance `(number)` The distance ahead
Returns
`(Patch | undefined)`: The patch at the distance ahead of this Turtle
▸ patchRightAndAhead(angle, distance)
src/Turtle.js

Return the patch angle to the right and ahead by distance Return undefined if the distance puts the patch off-world

patchRightAndAhead(angle: number, distance: number): (Patch | undefined)
Parameters
angle `(number)` The angle to the right
distance `(number)` The distance ahead
Returns
`(Patch | undefined)`: The patch found, or undefined if off-world
▸ patchLeftAndAhead(angle, distance)
src/Turtle.js

Return the patch angle to the left and ahead by distance Return undefined if the distance puts the patch off-world

patchLeftAndAhead(angle: number, distance: number): (Patch | undefined)
Parameters
angle `(number)` The angle to the left
distance `(number)` The distance ahead
Returns
`(Patch | undefined)`: The patch found, or undefined if off-world
▸ canMove(distance)
src/Turtle.js

Can I move forward by distance and not be off-world?

canMove(distance: number): Boolean
Parameters
distance `(number)` The distance ahead
Returns
`Boolean`: True if moving forward by distance is on-world
▸ distanceXY(x, y, z)
src/Turtle.js

Distance from this turtle to x, y No off-world test done.

2.5D: use z too if both z & this.z exist.

distanceXY(x: number, y: number, z: (number | undefined)): any
Parameters
x `(number)`
y `(number)`
z `((number | undefined) = `null`)`
Returns
`any`:
▸ distance(agent)
src/Turtle.js

Return distance from me to the Patch or Turtle

2.5D: use z too if both agent.z and this.z exist

distance(agent: any): any
Parameters
agent `(any)`
Returns
`any`:
▸ dx
src/Turtle.js

A property for the x-increment if the turtle were to take one step forward in its current heading.

dx
▸ dy
src/Turtle.js

A property for the y-increment if the turtle were to take one step forward in its current heading.

dy
▸ towards(agent)
src/Turtle.js

Return the heading towards the Patch or Turtle given.

towards(agent: (Patch | Turtle)): number
Parameters
agent `((Patch | Turtle))` The agent who's angle from this Turtle we use
Returns
`number`: The angle towards the agent
▸ towardsXY(x, y)
src/Turtle.js

Return the heading towards the given x,y coordinates.

towardsXY(x: number, y: number): number
Parameters
x `(number)` The x coordinarte
y `(number)` The y coordinarte
Returns
`number`: The angle towards x,y
▸ patchAt(dx, dy)
src/Turtle.js

The patch at dx, dy from my current position. Return undefined if off-world

patchAt(dx: number, dy: number): (Patch | undefined)
Parameters
dx `(number)` The delta x ahead
dy `(number)` The delta y ahead
Returns
`(Patch | undefined)`: The patch dx, dy ahead; undefined if off-world
▸ patchAtHeadingAndDistance(heading, distance)
src/Turtle.js

Return the patch at the absolute, not relative heading and distance from this turtle. Return undefined if off-world

Use the Left/Right versions for relative heading.

patchAtHeadingAndDistance(heading: number, distance: number): (Patch | undefined)
Parameters
heading `(number)` The absolute angle from this turtle
distance `(number)` The distance ahead
Returns
`(Patch | undefined)`: The Patch, or undefined if off-world
▸ otherEnd(l)
src/Turtle.js

Return the other end of this link from me. Link must include me!

See links property for all my links, if any.

otherEnd(l: Link): Turtle
Parameters
l `(Link)`
Returns
`Turtle`: The other turtle making this Link
▸ linkNeighbors()
src/Turtle.js

Return all turtles linked to me. Basically me.otherEnd of all my links.

linkNeighbors(): Array
Returns
`Array`: All the turtles linked to me
▸ isLinkNeighbor(t)
src/Turtle.js

Is the given Turtle linked to me?

isLinkNeighbor(t: Turtle): Boolean
Parameters
t `(Turtle)`
Returns
`Boolean`:

### Turtles

src/Turtles.js

A Turtle is an object living on the Patches world. Their coordinates are floats, unlike Patches with integer coordinates. They can morph between types of turtles (breeds) and storee information, both within themselves but also on Patches and Links.

The Turtles (plural) array, (AgentSet) is a collection of Turtle objects that the Turtles array creates and manages.

You do not create either individual Turtle objects, the Turtles array does. You also do not create the Turtles array, class Model does.

You use both, however, using the methods they both provide.

new Turtles(model: Model, AgentClass: (Turtle | Turtle3d), name: string, baseSet: (null | Turtles))

Extends AgentSet

Parameters
model `(Model)` The model I belong to
AgentClass `((Turtle | Turtle3d))` The Turtle class
name `(string)` The name of this new Turtles instance
baseSet `((null | Turtles) = `null`)` Used to create a breed subclass
Instance Members
▸ createOne(initFcn)
src/Turtles.js

Create a single Turtle, adding it to this Turtles array. The init function is called to initialize the new Turtle. Returns the new Turtle.

createOne(initFcn: Function): Turtle
Parameters
initFcn `(Function = `turtle=>{}`)`
Returns
`Turtle`: The newly created Turtle
▸ create(num, initFcn)
src/Turtles.js

Create num Turtles, adding them to this Turtles array. The init function is called to initialize the new Turtle. Returns an array of the new Turtles

create(num: any, initFcn: Function): Array
Parameters
num `(any)`
initFcn `(Function = `turtle=>{}`)`
Returns
`Array`: The newly created Turtles
▸ closestTurtle(x, y, radius)
src/Turtles.js

Return the closest turtle within radius distance of x,y. Return null if no turtles within radius. If I am a breed, return the closest fellow breed.

closestTurtle(x: number, y: number, radius: number): Turtle
Parameters
x `(number)` X coordinate
y `(number)` Y coordinate
radius `(number)` Radius in patches units
Returns
`Turtle`: The closest Turtle
▸ inPatches(patches)
src/Turtles.js

Return an array of Turtles within the array of patchs. If I am a breed, return only the Turtles of my breed.

inPatches(patches: Array<Patch>): AgentList
Parameters
patches `(Array<Patch>)` Array of patches
Returns
`AgentList`: The turtles withn the Patches array.
▸ inPatchRect(turtle, dx, dy, meToo)
src/Turtles.js

Return an array of Turtles within the dx,dy patchRect centered on turtle. If I am a breed, return only the Turtles of my breed.

inPatchRect(turtle: Turtle, dx: number, dy: number, meToo: boolean): AgentList
Parameters
turtle `(Turtle)` The Turtle at the patchRect center.
dx `(number)` The integer x radius of the patchRect
dy `(number = `dx`)` The integer y radius of the patchRect
meToo `(boolean = `false`)` Whether or not to return me as well
Returns
`AgentList`: The turtles within the patchRect
▸ inPatchRectXY(x, y, dx, dy, meToo)
src/Turtles.js

Return an array of Turtles within the dx,dy patchRect centered on x,y. If I am a breed, return only the Turtles of my breed.

inPatchRectXY(x: number, y: number, dx: number, dy: number, meToo: boolean): AgentList
Parameters
x `(number)` the patchRect center's integer x value
y `(number)` the patchRect center's integer y value
dx `(number)` The integer x radius of the patchRect
dy `(number = `dx`)` The integer y radius of the patchRect
meToo `(boolean = `false`)` Whether or not to return me as well
Returns
`AgentList`: The turtles within the patchRect
▸ inRadius(turtle, radius, meToo)
src/Turtles.js

Return all the Turtles within radius of me. If I am a breed, return only fellow breeds.

inRadius(turtle: Turtle, radius: number, meToo: boolean): AgentList
Parameters
turtle `(Turtle)`
radius `(number)`
meToo `(boolean = `false`)` Whether or not to return me as well
Returns
`AgentList`: The turtles within radius of me
▸ inCone(turtle, radius, coneAngle, meToo)
src/Turtles.js

Return all the Turtles with a cone of me. The cone is coneAngle wide, centered on my heading. If I am a breed, return only fellow breeds.

inCone(turtle: Turtle, radius: number, coneAngle: any, meToo: boolean): AgentList
Parameters
turtle `(Turtle)`
radius `(number)`
coneAngle `(any)`
meToo `(boolean = `false`)` Whether or not to return me as well
Returns
`AgentList`: The turtles within the cone.
▸ layoutCircle(radius, center)
src/Turtles.js

Position the Turtles in this breed in an equally spaced circle of the given center and radius. The turtle headings will be away from the center.

layoutCircle(radius: number, center: Array)
Parameters
radius `(number = `this.model.world.maxX*0.9`)` The circle's radius
center `(Array = `[0,0]`)` An x,y array

### Link

src/Link.js

Class Link instances form a link between two Turtles, forming a graph with the Turtles being the nodes, and the Links the edges.

TODO: Document Link properties and methods.

new Link()

### Links

src/Links.js

Links are a collection of all the Link objects between turtles.

new Links()

Extends AgentSet

### Patch

src/Patch.js

Class Patch instances represent a square on the Patches grid. They hold variables that are in the patches the turtles live on. The set of all patches is the world on which the turtles live and the model runs.

TODO: Document Patch properties and methods.

new Patch()
Instance Members
▸ neighbors
src/Patch.js

A list of this patch's 8 Moore neighbors.

neighbors
▸ neighbors4
src/Patch.js

A list of this patch's 4 Von Neumann neighbors (north, south, east, west).

neighbors4

### Patches

src/Patches.js

Patches are the world other AgentSets live on. They define a coord system from the Model's World values: minX, maxX, minY, maxY, (minZ, maxZ) (z optional) Patches form a grid of Patch objects which can store world data (elevation, fires, ant pheromones, buildings, roads, gis spatial data, water and so on)

Created by class Model. Used by modeler in their Model subclass

new Patches(model: Model, AgentClass: Patch, name: string)

Extends AgentSet

Parameters
model `(Model)` An instance of class Model
AgentClass `(Patch)` The Patch class managed by Patches
name `(string)` Name of the AgentSet
Instance Members
▸ neighbors(patch)
src/Patches.js

Return the 8 patch "Moore" neighbors of the given patch. Will be less than 8 on the edge of the patches

neighbors(patch: Patch): AgentList
Parameters
patch `(Patch)` a Patch instance
Returns
`AgentList`: An array of the neighboring patches
▸ neighbors4(patch)
src/Patches.js

Return the 4 patch "Van Neumann" neighbors of the given patch. Will be less than 4 on the edge of the patches

neighbors4(patch: Patch): AgentList
Parameters
patch `(Patch)` a Patch instance
Returns
`AgentList`: An array of the neighboring patches
▸ importDataSet(dataSet, property, useNearest)
src/Patches.js

Assign a DataSet's values into the patches as the given property name

importDataSet(dataSet: DataSet, property: string, useNearest: boolean)
Parameters
dataSet `(DataSet)` An instance of DataSet
property `(string)` A Patch property name
useNearest `(boolean = `false`)` Resample to nearest dataset value?
▸ exportDataSet(property, Type)
src/Patches.js

Extract a property from each Patch as a DataSet

exportDataSet(property: string, Type: Type): DataSet
Parameters
property `(string)` The patch numeric property to extract
Type `(Type = `Array`)` The DataSet array's type
Returns
`DataSet`: A DataSet of the patche's values
▸ patchIndex(x, y)
src/Patches.js

Return index into Patches given valid x,y integers

patchIndex(x: number, y: number): number
Parameters
x `(number)` Integer X value
y `(number)` Integer Y value
Returns
`number`: Integer index into Patches array

### AgentSet

src/AgentSet.js

A model's Patches, Turtles, Links, are all subclasses of AgentSet.

AgentSets are AgentArrays that are factories for their own Agents. That means you do not call `new Turtle()`, rather Turtles will create the Turtle instances, adding them to itself.

Finally, a Breed is simply a subarray of Patches, Turtles, Links. Patches could have a Streets breed, Turtles could have Cops and Robbers breeds, and Links Spokes and Rim breeds

AgentSets are not created directly by modelers. Instead, class Model creates them along with their Breeds. You can easily skip this initially, instead simply understand AgentSets are the basis for Patches, Turtles, Links & Breeds

new AgentSet(model: Model, AgentClass: (Patch | Turtle | Link), name: String, baseSet: (Patches | Turtles | Links))

Extends AgentArray

Parameters
model `(Model)` Instance of Class Model to which I belong
AgentClass `((Patch | Turtle | Link))` Class of items stored in this AgentSet
name `(String)` Name of this AgentSet. Ex: Patches
baseSet `((Patches | Turtles | Links) = `null`)` If a Breed, it's parent AgentSet
Static Members
▸ species
src/AgentSet.js

Magic to return AgentArrays rather than AgentSets Symbol.species

species
Instance Members
▸ protoMixin(agentProto, AgentClass)
src/AgentSet.js

Add common variables to an Agent being added to this AgentSet.

Each Agent has it's AgentSet and the Model instance. It also has an id, set by the AgentSet's global ID.

The Agent also has three methods added: setBreed, getBreed, isBreed.

protoMixin(agentProto: Object, AgentClass: (Patch | Turtle | Link))
Parameters
agentProto `(Object)` A new instance of the Agent being added
AgentClass `((Patch | Turtle | Link))` It's Class
▸ newBreed(name)
src/AgentSet.js

Create a subarray of this AgentSet. Example: create a people breed of Turtles:

`people = turtles.newBreed('people')`

newBreed(name: String): AgentSet
Parameters
name `(String)` The name of the new breed AgentSet
Returns
`AgentSet`: A subarray of me
▸ isBreedSet()
src/AgentSet.js
isBreedSet(): boolean
Returns
`boolean`: true if I am a baseSet subarray
▸ isBaseSet()
src/AgentSet.js
isBaseSet(): boolean
Returns
`boolean`: true if I am a Patches, Turtles or Links AgentSet
▸ withBreed(breed)
src/AgentSet.js

Return breeds in a subset of an AgentSet

Ex: patches.inRect(5).withBreed(houses)

withBreed(breed: AgentSet): AgentArray
Parameters
breed `(AgentSet)` A breed AgentSet
Returns
`AgentArray`:
▸ addAgent(o)
src/AgentSet.js

Add an Agent to this AgentSet. Only used by factory methods. Adds the `id` property to Agent. Increment AgentSet `ID`.

addAgent(o: Object): Object
Parameters
o `(Object = `undefined`)` An Agent to be added to this AgentSet
Returns
`Object`: The input Agent, bound to this AgentSet.
▸ clear()
src/AgentSet.js

Remove all Agents from this AgentSet using agent.die() for each agent.

clear()
▸ removeAgent(o)
src/AgentSet.js

Remove an Agent from this AgentSet

removeAgent(o: Object): AgentSet
Parameters
o `(Object)` The Agent to be removed
Returns
`AgentSet`: This AgentSet with the Agent removed
▸ setDefault(name, value)
src/AgentSet.js

Set a default value shared by all Agents in this AgentSet

setDefault(name: String, value: any): AgentSet
Parameters
name `(String)` The name of the shared value
value `(any)`
Returns
`AgentSet`: This AgentSet
▸ getDefault(name)
src/AgentSet.js

Return a default, shared value

getDefault(name: String): any
Parameters
name `(String)` The name of the default
Returns
`any`: The default value
▸ setBreed(a)
src/AgentSet.js

Move an agent from its AgentSet/breed to be in this AgentSet/breed

setBreed(a: Agent): Agent
Parameters
a `(Agent)` An agent, a member of another AgentSet
Returns
`Agent`: The updated agent
▸ ask(fcn)
src/AgentSet.js

Call fcn(agent, index, array) for each item in AgentArray. Index & array optional. Overrides AgentArray's ask with additional guards for modifications in AgentSet's array.

ask(fcn: Function)
Parameters
fcn `(Function)` fcn(agent, index?, array?)
▸ askSet(fcn)
src/AgentSet.js

A much stronger version of ask(fcn) with stronger mutability guards.

askSet(fcn: Function)
Parameters
fcn `(Function)` fcn(agent, index?, array?)

### AgentArray

src/AgentArray.js

Subclass of Array with convenience methods used by NetLogo. Tipically the items in the array are Objects but can be any type.

new AgentArray(args: any)

Extends Array

Parameters
args `(any)` Zero or more items in Array
Static Members
▸ species
src/AgentArray.js

Magic to return AgentArrays rather than AgentList or other AgentArray subclasses when using AA methods Symbol.species

species
▸ fromArray(array)
src/AgentArray.js

Convert an existing Array to an AgentArray "in place". Use array.slice() if a new array is wanted

fromArray(array: Array): AgentArray
Parameters
array `(Array)` Array to convert to AgentArray
Returns
`AgentArray`: array converted to AgentArray
Instance Members
▸ toArray()
src/AgentArray.js

See World and [MyClass's foo property]World#bboxTransform. Convert this AgentArray to Array in-place

toArray(): Array
Returns
`Array`: This AgentArray converted to Array
▸ isEmpty()
src/AgentArray.js

Return true if there are no items in this Array

isEmpty(): boolean
Returns
`boolean`:
Example

    new AgentArray().isEmpty()
     //=> true

    aa.isEmpty()
     //=> false

▸ first()
src/AgentArray.js

Return first item in this array. Returns undefined if empty.

first(): any
Returns
`any`:
Example

    aa.first()
     //=> { x: 0, y: 0 }

▸ last()
src/AgentArray.js

Return last item in this array. Returns undefined if empty.

last(): any
Returns
`any`:
Example

    aa.last()
     //=>  { x: 1, y: 0 }

▸ atIndex(i)
src/AgentArray.js

Return at index. Returns undefined if empty. Wrap the index to be within the array.

atIndex(i: any): any
Parameters
i `(any)`
Returns
`any`:
Example

    aa.atIndex(aa.length)
     //=>  { x: 0, y: 0 }

▸ all(fcn)
src/AgentArray.js

Return true if fcn(element) returns true for each element in this array. Same as Array.every, using NetLogo's name

all(fcn: Function): boolean
Parameters
fcn `(Function)` fcn(element) return boolean
Returns
`boolean`: true if fcn returns true for all elements
▸ props(key, type)
src/AgentArray.js

Return array of property values from this array's objects. Array type is specified, defaults to AgentArray

props(key: String, type: Array): Array
Parameters
key `(String)` Property name
type `(Array = `AgentArray`)` Type of array (Array, Uint8Array, ...)
Returns
`Array`: Array of given type
Example

    aa.props('x')
     //=> [0, 0, 1]

    aa.props('y')
     //=> [0, 1, 0]

▸ typedSample(obj)
src/AgentArray.js

Creates an Object of Arrays, one Array per each property in obj. Obj is key, arrayType pairs: x: Float32Array This is advanced, used for web workers, very large data sets, and remote communication

typedSample(obj: Object): Object
Parameters
obj `(Object)` Object of prop, array type pairs
Returns
`Object`:
Example

    aa.typedSample({x: Uint8Array, y: Uint8Array})
     //=> {x: new Uint8Array([0, 0, 1]), y: new Uint8Array([0, 1, 0])}

▸ uniq()
src/AgentArray.js

Return new AgentArray of the unique values of this array

uniq(): AgentArray
Returns
`AgentArray`:
▸ forLoop(fcn)
src/AgentArray.js

Call fcn(agent, index, array) for each item in AgentArray. Index & array optional. Array assumed not mutable. Note: 5x+ faster than this.forEach(fcn)

forLoop(fcn: Function): this
Parameters
fcn `(Function)` fcn(agent, [index] , [array] )
Returns
`this`: Return this for chaining.
▸ ask(fcn)
src/AgentArray.js

Call fcn(agent, index, array) for each item in AgentArray. Index & array optional. Array can shrink. If it grows, will not visit beyond original length. "ask" is NetLogo term.

ask(fcn: Function)
Parameters
fcn `(Function)` fcn(agent, [index] , [array] )
▸ with(fcn)
src/AgentArray.js

Use: turtles.with(t => t.foo > 20).ask(t => t.bar = true)

with(fcn: Function): AgentArray
Parameters
fcn `(Function)` fcn(agent, [index] , [array] )
Returns
`AgentArray`:
▸ clone()
src/AgentArray.js

Create copy of this AgentArray

clone(): any
Returns
`any`: AgentArray
▸ sortBy(reporter, ascending)
src/AgentArray.js

Return this AgentArray sorted by the reporter in ascending/descending order. If reporter is a string, convert to a fcn returning that property.

sortBy(reporter: function, ascending: boolean): AgentArray
Parameters
reporter `(function)`
ascending `(boolean = `true`)`
Returns
`AgentArray`:

## The Model

### Model

src/Model.js

Class Model is the primary interface for modelers, integrating the Patches/Patch Turtles/Turtle and Links/Link AgentSets .. i.e.:

- model.Patches: an array (Patches) of Patch instances
- model.Turtles: an array (Turtles) of Turtle instances
- model.Links: an array (Links) of Link instances
- model.breed: a sub-array of any of the three above.
- All of which are subclasses of (AgentSet).

Convention: Three abstract methods are provided by the modeler

- Startup(): (Optional) Called once to import images, data etc
- Setup(): Called to initialize the model state.
- Step(): Step the model. Will advance ticks if autoTick = true in constructor.

new Model(worldOptions: (Object | World), autoTick: boolean)
Parameters
worldOptions `((Object | World) = `World.defaultOptions()`)` Can be Object of min/max X,Y,Z values or an instance of World
autoTick `(boolean = `true`)` Automatically advancee tick count each step if true
Instance Members
▸ reset(worldOptions)
src/Model.js

Resets model to initial state w/ new Patches, Turtles, Links. The worldOptions will default to initial values but can be changed by modeler. Setup() often called after reset() to re-initialize the model.

reset(worldOptions: (Object | World))
Parameters
worldOptions `((Object | World) = `this.world`)` World object
▸ reset(worldOptions)
src/Model2D.js

Resets model to initial state w/ new Patches, Turtles, Links. The worldOptions will default to initial values but can be changed by modeler. Setup() often called after reset() to re-initialize the model.

reset(worldOptions: (Object | World))
Parameters
worldOptions `((Object | World) = `this.world`)` World object
▸ tick()
src/Model.js

Increment the tick cound. Not needed if autoTick true

tick()
▸ tick()
src/Model2D.js

Increment the tick cound. Not needed if autoTick true

tick()
▸ startup()
src/Model.js

An abstract method to perform one-time initialization.

startup()
▸ startup()
src/Model2D.js

An abstract method to perform one-time initialization.

startup()
▸ setup()
src/Model.js

An abstract method for initializing the model

Note: can be used with reset(). This will reinitialize the Patches, Turtles, Links for re-running the model

- reset()
- setup()

setup()
▸ setup()
src/Model2D.js

An abstract method for initializing the model

Note: can be used with reset(). This will reinitialize the Patches, Turtles, Links for re-running the model

- reset()
- setup()

setup()
▸ step()
src/Model.js

An abstract method to run the model one step.

step()
▸ step()
src/Model2D.js

An abstract method to run the model one step.

step()
▸ patchBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Patches. Used in the Exit model:

- this.patchBreeds('exits inside wall')

patchBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ patchBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Patches. Used in the Exit model:

- this.patchBreeds('exits inside wall')

patchBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ turtleBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Turtles. Used in Wallfollower model:

- this.turtleBreeds('lefty righty')

turtleBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ turtleBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Turtles. Used in Wallfollower model:

- this.turtleBreeds('lefty righty')

turtleBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ linkBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Links. Used in Roads model:

- this.linkBreeds('trips')

linkBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ linkBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Links. Used in Roads model:

- this.linkBreeds('trips')

linkBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ setGeometry(name)
src/Model2D.js

Set the Geometry of this Model

- radians: Set the model to use native Javascript angles.
  See Math module
- degrees: Use degrees rather than radians.
  The above with degree<>radian conversions done for you.
- heading: Use "Clock" geometry:
  Degrees with 0 "up" and angles Clockwise.

setGeometry(name: string)
Parameters
name `(string)` One of 'radians', 'degrees', 'heading'

### Model

src/Model2D.js

Class Model is the primary interface for modelers, integrating the Patches/Patch Turtles/Turtle and Links/Link AgentSets .. i.e.:

- model.Patches: an array (Patches) of Patch instances
- model.Turtles: an array (Turtles) of Turtle instances
- model.Links: an array (Links) of Link instances
- model.breed: a sub-array of any of the three above.
- All of which are subclasses of (AgentSet).

Convention: Three abstract methods are provided by the modeler

- Startup(): (Optional) Called once to import images, data etc
- Setup(): Called to initialize the model state.
- Step(): Step the model. Will advance ticks if autoTick = true in constructor.

new Model(worldOptions: (Object | World), autoTick: boolean)
Parameters
worldOptions `((Object | World) = `World.defaultOptions()`)` Can be Object of min/max X,Y,Z values or an instance of World
autoTick `(boolean = `true`)` Automatically advancee tick count each step if true
Instance Members
▸ reset(worldOptions)
src/Model.js

Resets model to initial state w/ new Patches, Turtles, Links. The worldOptions will default to initial values but can be changed by modeler. Setup() often called after reset() to re-initialize the model.

reset(worldOptions: (Object | World))
Parameters
worldOptions `((Object | World) = `this.world`)` World object
▸ reset(worldOptions)
src/Model2D.js

Resets model to initial state w/ new Patches, Turtles, Links. The worldOptions will default to initial values but can be changed by modeler. Setup() often called after reset() to re-initialize the model.

reset(worldOptions: (Object | World))
Parameters
worldOptions `((Object | World) = `this.world`)` World object
▸ tick()
src/Model.js

Increment the tick cound. Not needed if autoTick true

tick()
▸ tick()
src/Model2D.js

Increment the tick cound. Not needed if autoTick true

tick()
▸ startup()
src/Model.js

An abstract method to perform one-time initialization.

startup()
▸ startup()
src/Model2D.js

An abstract method to perform one-time initialization.

startup()
▸ setup()
src/Model.js

An abstract method for initializing the model

Note: can be used with reset(). This will reinitialize the Patches, Turtles, Links for re-running the model

- reset()
- setup()

setup()
▸ setup()
src/Model2D.js

An abstract method for initializing the model

Note: can be used with reset(). This will reinitialize the Patches, Turtles, Links for re-running the model

- reset()
- setup()

setup()
▸ step()
src/Model.js

An abstract method to run the model one step.

step()
▸ step()
src/Model2D.js

An abstract method to run the model one step.

step()
▸ patchBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Patches. Used in the Exit model:

- this.patchBreeds('exits inside wall')

patchBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ patchBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Patches. Used in the Exit model:

- this.patchBreeds('exits inside wall')

patchBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ turtleBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Turtles. Used in Wallfollower model:

- this.turtleBreeds('lefty righty')

turtleBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ turtleBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Turtles. Used in Wallfollower model:

- this.turtleBreeds('lefty righty')

turtleBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ linkBreeds(breedNames)
src/Model.js

Create breeds (sub-arrays) of Links. Used in Roads model:

- this.linkBreeds('trips')

linkBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ linkBreeds(breedNames)
src/Model2D.js

Create breeds (sub-arrays) of Links. Used in Roads model:

- this.linkBreeds('trips')

linkBreeds(breedNames: string)
Parameters
breedNames `(string)` A string of space separated breeds names
▸ setGeometry(name)
src/Model2D.js

Set the Geometry of this Model

- radians: Set the model to use native Javascript angles.
  See Math module
- degrees: Use degrees rather than radians.
  The above with degree<>radian conversions done for you.
- heading: Use "Clock" geometry:
  Degrees with 0 "up" and angles Clockwise.

setGeometry(name: string)
Parameters
name `(string)` One of 'radians', 'degrees', 'heading'

### World

src/World.js

Class World defines the coordinate system for the model. It has transforms for multiple coordinate systems.

The world is defined by an object with 6 properties:

         WorldOptions = {
             minX: integer,
             maxX: integer,
             minY: integer,
             maxY: integer,
             minZ: integer,
             maxZ: integer,
         }

new World(options: (World | WorldOptions | Object))
Parameters
options `((World | WorldOptions | Object) = `{}`)` Object with overrides for class properties
Static Members
▸ defaultOptions(maxX, maxY, maxZ)
src/World.js

Return a default options object, origin at center.

defaultOptions(maxX: number, maxY: number, maxZ: number): WorldOptions
Parameters
maxX `(number = `16`)` Integer max X value
maxY `(number = `maxX`)` Integer max Y value
maxZ `(number = `Math.max(maxX,maxY)`)` Integer max Z value
Returns
`WorldOptions`:
▸ defaultWorld(maxX, maxY, maxZ)
src/World.js

Factory to create a default World instance.

defaultWorld(maxX: number, maxY: number, maxZ: number): World
Parameters
maxX `(number = `16`)` Integer max X value
maxY `(number = `maxX`)` Integer max Y value
maxZ `(number = `Math.max(maxX,maxY)`)` Integer max Z value
Returns
`World`:
Instance Members
▸ randomPoint()
src/World.js

Return a random 2D point within the World

randomPoint(): Array
Returns
`Array`: A random x,y float array
▸ random3DPoint()
src/World.js

Return a random 3D point within the World

random3DPoint(): Array
Returns
`Array`: A random x,y,z float array
▸ randomPatchPoint()
src/World.js

Return a random Patch 2D integer point

randomPatchPoint(): Array
Returns
`Array`: A random x,y integer array
▸ isOnWorld(x, y, z)
src/World.js

Given x,y,z values return true if within the world

isOnWorld(x: number, y: number, z: number): boolean
Parameters
x `(number)` x value
y `(number)` y value
z `(number = `this.centerZ`)` z value
Returns
`boolean`: Whether or not on-world
▸ bboxTransform(minX, minY, maxX, maxY)
src/World.js

Return an instance of a bounding box 2D transform. It linearly interpolates between the given minX, minY, maxX, maxY, and the world's values of the same properties.

The parameters are in the popular geojson order: west, south, east, north

Useful for Canvas top-left transforms and geojson transforms.

bboxTransform(minX: number, minY: number, maxX: number, maxY: number): BBoxTransform
Parameters
minX `(number)` min bounding box x value
minY `(number)` min bounding box y value
maxX `(number)` max bounding box x value
maxY `(number)` max bounding box y value
Returns
`BBoxTransform`: Instance of the BBoxTransform

## The View

### TwoDraw

src/TwoDraw.js

Basic 2D view.

TODO: Document this class

new TwoDraw(model: any, viewOptions: any, drawOptions: any)

Extends TwoView

Parameters
model `(any)`
viewOptions `(any = `{}`)`
drawOptions `(any = `{}`)`

### ThreeDraw

src/ThreeDraw.js

Basic 3D view.

TODO: Document this class

new ThreeDraw(model: any, viewOptions: any, drawOptions: any)

Extends ThreeView

Parameters
model `(any)`
viewOptions `(any = `{}`)`
drawOptions `(any = `{}`)`

### Color

src/Color.js

A general color module, supporting css string colors, canvas2d pixel colors, webgl and canvas2d Uint8ClampedArray r,g,b,a arrays.

### CSS Color Strings.

CSS colors in HTML are strings, see Mozillas Color Reference, taking one of 7 forms:

- Names: over 140 color case-insensitive names like Red, Green, CadetBlue, etc.
- Hex, short and long form: #0f0, #ff10a0
- RGB: rgb(255, 0, 0), rgba(255, 0, 0, 0.5)
- HSL: hsl(120, 100%, 50%), hsla(120, 100%, 50%, 0.8)

See this wikipedia article on differences between HSL and HSB/HSV.

Color
Static Members
▸ rgbaCssColor(r, g, b, a)
src/Color.js

Convert 4 r,g,b,a ints in [0-255] ("a" defaulted to 255) to a css color string.

rgbaCssColor(r: any, g: any, b: any, a: any)
Parameters
r `(any)`
g `(any)`
b `(any)`
a `(any = `255`)`
▸ hslCssColor(h, s, l, a)
src/Color.js

Convert 4 ints, h,s,l,a, h in [0-360], s,l in [0-100]% a in [0-255] to a css color string.

NOTE: h=0 and h=360 are the same, use h in 0-359 for unique colors.

hslCssColor(h: any, s: any, l: any, a: any)
Parameters
h `(any)`
s `(any)`
l `(any)`
a `(any = `255`)`

## Interaction

### Mouse

src/Mouse.js

A NetLogo-like mouse handler.

TODO: Example usage.

new Mouse(canvas: any, world: any, callback: any)
Parameters
canvas `(any)`
world `(any)`
callback `(any = `(evt,mouse)=>{}`)`

## Utilities

An assortment of helper functions. To use: `import * as util from src/utils.js`.

### randomInt

src/utils.js

Returns a random int in [0, max)

randomInt
Parameters
max `(any)`

### randomInt2

src/utils.js

Returns a random int in [min, max)

randomInt2
Parameters
min `(any)`
max `(any)`

### randomFloat

src/utils.js

Returns a random float in [0, max)

randomFloat
Parameters
max `(any)`

### randomFloat2

src/utils.js

Returns a random float in [min, max)

randomFloat2
Parameters
min `(any)`
max `(any)`

## Other

### DataSet

src/DataSet.js

A DataSet is an object with width/height and an array of numbers of length = width * height.

The array can be a TypedArray or a JavaScript Array.

new DataSet(width: number, height: number, data: array)
Parameters
width `(number)` The integer width of the array
height `(number)` The integer height of the array
data `(array)` The array of numbers of length width * height
Static Members
▸ emptyDataSet(width, height, Type)
src/DataSet.js

Factory method returning an empty dataset of given width, height, dataType

emptyDataSet(width: number, height: number, Type: Object): DataSet
Parameters
width `(number)` The integer width of the array
height `(number)` The integer height of the array
Type `(Object)` Array or one of the typed array types
Returns
`DataSet`: The resulting DataSet with no values assigned