Constructor
new Particle(pos, vel, mass, radius, bounciness, charge, color)
Instantiates new Particle
Name | Type | Default | Description |
---|---|---|---|
pos | Vector2D | cartesian coordinates of the particle | |
vel | Vector2D | velocity of the particle | |
mass | Number | ||
radius | Number | ||
bounciness | Number | 1 | a value in [0,1] that represents the amount of energy retained after collision |
charge | Number | 0 | similar to real physical charge |
color | String | black | currently only supports HTML canvas colors format |
- Source
Extends
Methods
addNearBehavior(b) → {Boolean}
Adds a NearBehavior
to the particle if not added already
Name | Type | Description |
---|---|---|
b | NearBehavior |
- Source
true if successfully added
- Type:
- Boolean
addSelfBehavior(b) → {Boolean}
Adds a SelfBehavior
to the particle if not added already
Name | Type | Description |
---|---|---|
b | SelfBehavior |
- Source
true if successfully added
- Type:
- Boolean
applyAcceleration(a, timeStep)
Increments the velocity by an acceleration a
Name | Type | Description |
---|---|---|
a | Vector2D | |
timeStep | Number |
- Source
applyForce(f, timeStep)
Applies force f
to the velocity
Name | Type | Description |
---|---|---|
f | Vector2D | |
timeStep | Number |
- Source
applyVelocity(v, timeStep)
Increments the position by velocity v
Name | Type | Description |
---|---|---|
v | Vector2D | |
timeStep | Number |
- Source
clearBehaviors()
Clears all behaviors of the particle
- Source
getHashDimensions() → {Array.<Number>}
Computes the dimensions of the item for the HashGrid
.
- Overrides
- Source
- Type:
- Array.<Number>
getHashPos() → {Array.<Number>}
Computes the coordinate position for the item within the HashGrid
, expects center position.
- Overrides
- Source
- Type:
- Array.<Number>
removeNearBehavior(b) → {Boolean}
Removes NearBehavior
b
if the particle has b
Name | Type | Description |
---|---|---|
b | NearBehavior |
- Source
true if the action is successful
- Type:
- Boolean
removeSelfBehavior(b) → {Boolean}
Removes SelfBehavior
b
if the particle has b
Name | Type | Description |
---|---|---|
b | SelfBehavior |
- Source
true if the action is successful
- Type:
- Boolean