Turtles

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.

Constructor

new Turtles(model, AgentClass, name, baseSetopt)

Parameters:
NameTypeAttributesDefaultDescription
modelModel

The model I belong to

AgentClassTurtle | Turtle3d

The Turtle class

namestring

The name of this new Turtles instance

baseSetnull | Turtles<optional>
null

Used to create a breed subclass

Methods

createOne(initFcnopt) → {Turtle}

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

Parameters:
NameTypeAttributesDefaultDescription
initFcnfunction<optional>
turtle => {}
Returns:

The newly created Turtle

Type: 
Turtle

create(number, initFcnopt) → {Array}

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

Parameters:
NameTypeAttributesDefaultDescription
numbernumber

Number of Turtles to create

initFcnfunction<optional>
turtle => {}

A function to initialize new turtles.

Returns:

The newly created Turtles

Type: 
Array

closestTurtle(x, y, radius) → {Turtle}

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.

Parameters:
NameTypeDescription
xnumber

X coordinate

ynumber

Y coordinate

radiusnumber

Radius in patches units

Returns:

The closest Turtle

Type: 
Turtle

inPatches(patches) → {AgentList}

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

Parameters:
NameTypeDescription
patchesArray.<Patch>

Array of patches

Returns:

The turtles withn the Patches array.

Type: 
AgentList

inPatchRect(turtle, dx, dyopt, meTooopt) → {AgentList}

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.

Parameters:
NameTypeAttributesDefaultDescription
turtleTurtle

The Turtle at the patchRect center.

dxnumber

The integer x radius of the patchRect

dynumber<optional>
dx

The integer y radius of the patchRect

meTooboolean<optional>
false

Whether or not to return me as well

Returns:

The turtles within the patchRect

Type: 
AgentList

inPatchRectXY(x, y, dx, dyopt, meTooopt) → {AgentList}

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.

Parameters:
NameTypeAttributesDefaultDescription
xnumber

the patchRect center's integer x value

ynumber

the patchRect center's integer y value

dxnumber

The integer x radius of the patchRect

dynumber<optional>
dx

The integer y radius of the patchRect

meTooboolean<optional>
false

Whether or not to return me as well

Returns:

The turtles within the patchRect

Type: 
AgentList

inRadius(turtle, radius, meTooopt) → {AgentList}

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

Parameters:
NameTypeAttributesDefaultDescription
turtleTurtle
radiusnumber
meTooboolean<optional>
false

Whether or not to return me as well

Returns:

The turtles within radius of me

Type: 
AgentList

inCone(turtle, radius, meTooopt) → {AgentList}

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.

Parameters:
NameTypeAttributesDefaultDescription
turtleTurtle
radiusnumber
meTooboolean<optional>
false

Whether or not to return me as well

Returns:

The turtles within the cone.

Type: 
AgentList

layoutCircle(radiusopt, centeropt)

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.

Parameters:
NameTypeAttributesDefaultDescription
radiusnumber<optional>
this.model.world.maxX * 0.9

The circle's radius

centerArray<optional>
[0, 0]

An x,y array