On this page

# 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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`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 | <optional> | null | Used to create a breed subclass

Source
  - Turtles.js, line 25

## 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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`initFcn` | function | <optional> | turtle => {} |

Source
  - Turtles.js, line 39

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`number` | number |  |  | Number of Turtles to create
`initFcn` | function | <optional> | turtle => {} | A function to initialize new turtles.

Source
  - Turtles.js, line 62

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:

Name | Type | Description
--- | --- | ---
`x` | number | X coordinate
`y` | number | Y coordinate
`radius` | number | Radius in patches units

Source
  - Turtles.js, line 78

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:

Name | Type | Description
--- | --- | ---
`patches` | Array.<Patch> | Array of patches

Source
  - Turtles.js, line 92

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`turtle` | Turtle |  |  | The Turtle at the patchRect center.
`dx` | number |  |  | The integer x radius of the patchRect
`dy` | number | <optional> | dx | The integer y radius of the patchRect
`meToo` | boolean | <optional> | false | Whether or not to return me as well

Source
  - Turtles.js, line 110

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`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 | <optional> | dx | The integer y radius of the patchRect
`meToo` | boolean | <optional> | false | Whether or not to return me as well

Source
  - Turtles.js, line 126

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`turtle` | Turtle |  |  |
`radius` | number |  |  |
`meToo` | boolean | <optional> | false | Whether or not to return me as well

Source
  - Turtles.js, line 140

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`turtle` | Turtle |  |  |
`radius` | number |  |  |
`meToo` | boolean | <optional> | false | Whether or not to return me as well

Source
  - Turtles.js, line 154

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:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`radius` | number | <optional> | this.model.world.maxX * 0.9 | The circle's radius
`center` | Array | <optional> | [0, 0] | An x,y array

Source
  - Turtles.js, line 167

Type anything to view search result