Class: ABM.Patch
Defined in: | src/patch.coffee |
Overview
Patch instances represent a rectangle on a grid. They hold variables that are in the patches the agents live on. The set of all patches (@model.patches) is the world on which the agents live and the model runs.
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}.
- color =
-
u
The color of the agent patch.
-
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.
- agents =
-
null
Agents on this patch.
Instance Method Summary
- # (void) toString() Returns a string representation of the patch.
- # (void) empty() Returns true if the patch is empty.
- # (void) isOnEdge() Returns true if this patch is on the edge of the grid.
- # (void) sprout(number = 1, breed = @model, init = function() {}) Factory: Create num new agents on this patch.
- # (void) distance(point, options) Return distance in patch coordinates from me to given agent/patch using patch topology (isTorus).
- # (void) neighbors(options) Get neighbors for patch.
- # (void) neighborAgents(options) Get agents on neigboring patches.
- # (void) diamondNeighbors(range, meToo) Not to be used directly, will not cache.
- # (void) draw(context) Draw the patch and its text label if there is one.
Constructor Details
#
(void)
constructor(position)
New Patch: Just set position {x: some integer, y: some integer}.
Instance Method Details
#
(void)
toString()
Returns a string representation of the patch.
#
(void)
empty()
Returns true if the patch is empty.
#
(void)
isOnEdge()
Returns true if this patch is on the edge of the grid.
#
(void)
sprout(number = 1, breed = @model, init = function() {})
Factory: Create num new agents on this patch. The optional init proc is called on the new agent after inserting in its agentSet.
#
(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)
Get neighbors for patch.
#
(void)
neighborAgents(options)
Get agents on neigboring patches.
#
(void)
diamondNeighbors(range, meToo)
Not to be used directly, will not cache.
#
(void)
draw(context)
Draw the patch and its text label if there is one.