Members
links
Returns an array of the Links that have this Turtle as one of the end points
patch
Return the patch this Turtle is on. Return null if Turtle off-world.
heading
Return this Turtle's heading
heading
Sets this Turtle's heading
(readonly) dx
A property for the x-increment if the turtle were to take one step forward in its current heading.
(readonly) dy
A property for the y-increment if the turtle were to take one step forward in its current heading.
Methods
die()
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
hatch(numopt, breedopt, initopt) → {Array}
Factory method: create num new turtles at this turtle's location.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
num | number | <optional> | 1 | The number of new turtles to create |
breed | AgentSet | <optional> | this.agentSet | The type of turtles to create, defaults to my type |
init | function | <optional> | turtle => {} | A function to initialize the new turtles, defaults to no-op |
An Array of the new Turtles, generally ignored due to the init function
- Type:
- Array
subtractHeading(heading) → {Angle}
Computes the difference between the my heading and the given heading, the smallest angle by which t could be rotated to produce heading.
Name | Type | Description |
---|---|---|
heading | Angle | The heading I wish to be roated to. |
- Type:
- Angle
setxy(x, y, zopt)
Set Turtles x, y position. If z given, override default z of 0.
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Turtle's x coord, a Float in patch space | |
y | number | Turtle's Y coord, a Float in patch space | |
z | number | | <optional> | Turtle's Z coord if given |
handleEdge(x, y, zopt)
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:
- 'die'
- 'wrap'
- 'bounce'
- 'clamp'
- 'random'
- a function called with the Turtle as it's argument
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Turtle's x coord | |
y | number | Turtle's y coord | |
z | number | | <optional> | Turtle's z coord if not undefined |
moveTo(agent)
Place the turtle at the given patch/turtle location
forward(d)
Move forward, along the Turtle's heading d units in Patch coordinates
Name | Type | Description |
---|---|---|
d | number | The distance to move |
rotate(angle)
Change Turtle's heading by angle
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by |
right(angle)
Turn Turtle right by angle
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by |
left(angle)
Turn Turtle left by angle
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by |
face(agent)
Turn turtle so at to be facing the given Turtle or Patch
facexy(x, y)
Turn turtle so at to be facing the given x, y patch coordinate
Name | Type | Description |
---|---|---|
x | number | The x coordinate |
y | number | The y coordinate |
patchAhead(distance) → {Patch|undefined}
Return the patch ahead of this turtle by distance. Return undefined if the distance puts the patch off-world
Name | Type | Description |
---|---|---|
distance | number | The distance ahead |
The patch at the distance ahead of this Turtle
- Type:
- Patch |
undefined
patchRightAndAhead(angle, distance) → {Patch|undefined}
Return the patch angle to the right and ahead by distance Return undefined if the distance puts the patch off-world
Name | Type | Description |
---|---|---|
angle | number | The angle to the right |
distance | number | The distance ahead |
The patch found, or undefined if off-world
- Type:
- Patch |
undefined
patchLeftAndAhead(angle, distance) → {Patch|undefined}
Return the patch angle to the left and ahead by distance Return undefined if the distance puts the patch off-world
Name | Type | Description |
---|---|---|
angle | number | The angle to the left |
distance | number | The distance ahead |
The patch found, or undefined if off-world
- Type:
- Patch |
undefined
canMove(distance) → {Boolean}
Can I move forward by distance and not be off-world?
Name | Type | Description |
---|---|---|
distance | number | The distance ahead |
True if moving forward by distance is on-world
- Type:
- Boolean
distanceXY(x, y, zopt) → {number}
Distance from this turtle to x, y No off-world test done.
2.5D: use z too if both z & this.z exist.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number | |||
y | number | |||
z | number | | <optional> | null |
distance in patch coordinates.
- Type:
- number
distance(agent) → {number}
Return distance from me to the Patch or Turtle
2.5D: use z too if both agent.z and this.z exist
distance in patch coordinates.
- Type:
- number
towards(agent) → {number}
Return the heading towards the Patch or Turtle given.
The angle towards the agent
- Type:
- number
towardsXY(x, y) → {number}
Return the heading towards the given x,y coordinates.
Name | Type | Description |
---|---|---|
x | number | The x coordinarte |
y | number | The y coordinarte |
The angle towards x,y
- Type:
- number
patchAt(dx, dy) → {Patch|undefined}
The patch at dx, dy from my current position. Return undefined if off-world
Name | Type | Description |
---|---|---|
dx | number | The delta x ahead |
dy | number | The delta y ahead |
The patch dx, dy ahead; undefined if off-world
- Type:
- Patch |
undefined
patchAtHeadingAndDistance(heading, distance) → {Patch|undefined}
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.
Name | Type | Description |
---|---|---|
heading | number | The absolute angle from this turtle |
distance | number | The distance ahead |
The Patch, or undefined if off-world
- Type:
- Patch |
undefined
otherEnd(l) → {Turtle}
Return the other end of this link from me. Link must include me!
See links property for all my links, if any.
Name | Type | Description |
---|---|---|
l | Link |
The other turtle making this Link
- Type:
- Turtle
linkNeighbors() → {Array}
Return all turtles linked to me. Basically me.otherEnd of all my links.
All the turtles linked to me
- Type:
- Array
isLinkNeighbor(t) → {Boolean}
Is the given Turtle linked to me?
Name | Type | Description |
---|---|---|
t | Turtle |
- Type:
- Boolean