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 =
null

Unique ID, set by BreedSet create() factory method.

breed =
null

The BreedSet this agent belongs to.

position =
null

Position on the patch grid, hash with patch coordinates {x: some float, y: float}.

patch =
null

The patch the agent is on.

size =
1

Agents' size in patch coordinates.

color =
null

The color of the agent, defaults to ABM.Color.random().

strokeColor =
null

Color of the border of the agent.

shape =
"default"

The shape name of the agent.

hidden =
false

Whether or not to draw this agent.

label =
null

Text for a label.

labelColor =
u

The color of the label.

labelOffset =
{
  x: 0,
  y: 0
}

The x, y offset of the label.

penDown =
false

If my pen is down, I draw my path between changes in x, y.

penSize =
1

The pen thickness in pixels.

heading =
null

The direction the agent is pointed in, in radians.

sprite =
null

Sprite image of the agent, for optimized drawing.

null

Array of links to/from the agent as an endpoint.

Instance Method Summary

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: } or {right: } to specify a direction in a more legible way.

# (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.

Return links where I am the "from" agent in links.create.

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.

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: