Class: ABM.Agent
| Defined in: | src/agent.coffee |
Overview
Agent instances represent the dynamic, behavioral element of the ABM. Each agent knows the patch it is on, and interacts with that and other patches, as well as other agents.
Variables Summary
- id =
-
nullUnique ID, set by BreedSet create() factory method.
- breed =
-
nullThe BreedSet this agent belongs to.
- position =
-
nullPosition on the patch grid, hash with patch coordinates {x: some float, y: float}.
- patch =
-
nullThe patch the agent is on.
- size =
-
1Agents' size in patch coordinates.
- color =
-
nullThe color of the agent, defaults to ABM.Color.random().
- strokeColor =
-
nullColor of the border of the agent.
- shape =
-
"default"The shape name of the agent.
-
falseWhether or not to draw this agent.
- label =
-
nullText for a label.
- labelColor =
-
uThe color of the label.
- labelOffset =
-
{ x: 0, y: 0 }The x, y offset of the label.
- penDown =
-
falseIf my pen is down, I draw my path between changes in x, y.
- penSize =
-
1The pen thickness in pixels.
- heading =
-
nullThe direction the agent is pointed in, in radians.
- sprite =
-
nullSprite image of the agent, for optimized drawing.
- links =
-
nullArray of links to/from the agent as an endpoint.
Instance Method Summary
- # (void) toString() Return a string representation of the agent.
- # (void) moveTo(point) Place the agent at the given patch/agent location.
- # (void) moveOff() Moves the agent off the grid, making him lose his patch.
- # (void) forward(distance = 1, options = {}) Move forward (along heading) by distance units (patch coordinates), using patch topology (isTorus).
- # (void) rotate(options) Change current heading by radians.
- # (void) face(point) Set heading towards given agent/patch using patch topology.
- # (void) distance(point, options) Return distance in patch coordinates from me to given agent/patch using patch topology (isTorus).
- # (void) neighbors(options) Returns the neighbors (agents) of this agent.
- # (void) die() Remove myself from the model.
- # (void) hatch(number = 1, breed = @model, init = function() {}) Factory: create num new agents at this agents location.
- # (void) otherEnd(link) Return other end of the link.
- # (void) outLinks() Return links where I am the "from" agent in links.create.
- # (void) inLinks() Return links where I am the "to" agent in links.create.
- # (void) linkNeighbors() All agents linked to me.
- # (void) inLinkNeighbors() The other end of myInLinks.
- # (void) outLinkNeighbors() The other end of myOutinks.
- # (void) draw(context) Draw the agent, instanciating a sprite if required.
- # (void) setSprite(sprite) Set an individual agent's sprite, synching its color, shape, size.
- # (void) stamp() Draw the agent on the drawing layer, leaving permanent image.
Constructor Details
#
(void)
constructor()
Initializes instance variables.
Called by BreedSet create factory, not user.
Instance Method Details
#
(void)
toString()
Return a string representation of the agent.
#
(void)
moveTo(point)
Place the agent at the given patch/agent location.
Place the agent at the given point (floats) in patch coordinates using patch topology (isTorus).
#
(void)
moveOff()
Moves the agent off the grid, making him lose his patch.
#
(void)
forward(distance = 1, options = {})
Move forward (along heading) by distance units (patch coordinates), using patch topology (isTorus).
#
(void)
rotate(options)
Change current heading by radians.
Pass a number in radians which can be + (left) or - (right).
Or pass {left:
#
(void)
face(point)
Set heading towards given agent/patch using patch topology.
#
(void)
distance(point, options)
Return distance in patch coordinates from me to given agent/patch using patch topology (isTorus).
Pass {euclidian: true} for always euclidian distance, and {dimension: true} for max distance along one dimension.
#
(void)
neighbors(options)
Returns the neighbors (agents) of this agent.
#
(void)
die()
Remove myself from the model. Includes removing myself from the agents agentset and removing any links I may have.
#
(void)
hatch(number = 1, breed = @model, init = function() {})
Factory: create num new agents at this agents location. The optional init proc is called on the new agent after inserting in its agentSet.
#
(void)
otherEnd(link)
Return other end of the link.
#
(void)
outLinks()
Return links where I am the "from" agent in links.create.
#
(void)
inLinks()
Return links where I am the "to" agent in links.create.
#
(void)
linkNeighbors()
All agents linked to me.
#
(void)
inLinkNeighbors()
The other end of myInLinks.
#
(void)
outLinkNeighbors()
The other end of myOutinks.
#
(void)
draw(context)
Draw the agent, instanciating a sprite if required.
#
(void)
setSprite(sprite)
Set an individual agent's sprite, synching its color, shape, size.
#
(void)
stamp()
Draw the agent on the drawing layer, leaving permanent image.