Class: Agent

Agent

new Agent()

Creates a new Agent. Agents are basic Flora elements that respond to forces like gravity, attraction, repulsion, etc. They can also chase after other Agents, organize with other Agents in a flocking behavior, and steer away from obstacles. They can also follow the mouse.
Source:

Extends

Methods

_align(items) → {Object}

Loops through a passed items array and calculates a force to apply to align with all items.
Parameters:
Name Type Description
items array An array of Flora items.
Source:
Returns:
A force to apply.
Type
Object

_cohesion(items) → {Object}

Loops through a passed items array and calculates a force to apply to stay close to all items.
Parameters:
Name Type Description
items array An array of Flora items.
Source:
Returns:
A force to apply.
Type
Object

_flock() → {Object}

Bundles flocking behaviors (separate, align, cohesion) into one call.
Source:
Returns:
This object's acceleration vector.
Type
Object

_follow(target) → {Object}

Calculates a steering force to apply to an object following another object. Agents with flow fields will use this method to calculate a steering force.
Parameters:
Name Type Description
target Object The object to follow.
Source:
Returns:
The force to apply.
Type
Object

<private> _seek(target) → {Object}

Calculates a steering force to apply to an object seeking another object.
Parameters:
Name Type Description
target Object The object to seek.
Source:
Returns:
The force to apply.
Type
Object

_separate(items) → {Object}

Loops through a passed items array and calculates a force to apply to avoid all items.
Parameters:
Name Type Description
items array An array of Flora items.
Source:
Returns:
A force to apply.
Type
Object

applyAdditionalForces() → {Object}

Applies Agent-specific forces.
Source:
Returns:
This object's acceleration vector.
Type
Object

init(opt_options=)

Initializes an instance.
Parameters:
Name Type Argument Default Description
opt_options= Object <optional>
A map of initial properties.
opt_options.followMouse boolean <optional>
false If true, object will follow mouse.
opt_options.maxSteeringForce number <optional>
10 Set the maximum strength of any steering force.
opt_options.seekTarget Object <optional>
null An object to seek.
opt_options.flocking boolean <optional>
false Set to true to apply flocking forces to this object.
opt_options.desiredSeparation number <optional>
Twice the object's default width Sets the desired separation from other objects when flocking = true.
opt_options.separateStrength number <optional>
1 The strength of the force to apply to separating when flocking = true.
opt_options.alignStrength number <optional>
1 The strength of the force to apply to aligning when flocking = true.
opt_options.cohesionStrength number <optional>
1 The strength of the force to apply to cohesion when flocking = true.
opt_options.flowField Object <optional>
null If a flow field is set, object will use it to apply a force.
opt_options.sensors = Array <optional>
A list of sensors attached to this object.
opt_options.motorSpeed number <optional>
2 Motor speed
opt_options.color Array <optional>
197, 177, 115 Color.
opt_options.borderWidth number <optional>
0 Border width.
opt_options.borderStyle string <optional>
'none' Border style.
opt_options.borderColor string | Array <optional>
'transparent' Border color.
opt_options.borderRadius number <optional>
0 Border radius.
Source: