Constructor
new World(canvas, width, height, xGrids, yGrids, timeStep, iterationPerFrame, constraintIteration)
Instantiates new World
instance
Name | Type | Default | Description |
---|---|---|---|
canvas | HTMLCanvasElement | HTML canvas where the elements are displayed | |
width | Number | width of world | |
height | Number | height of world | |
xGrids | Number | integer number of grid separations in the x direction | |
yGrids | Number | null | integer number of grid separations in the y direction |
timeStep | Number | 1 | change in time per solve iteration |
iterationPerFrame | Number | 1 | number of solve iterations per frame |
constraintIteration | Number | 1 | number of times constraints are solved per iteration |
- Source
Methods
addConstraint(c)
Adds a constraint to the world
Name | Type | Description |
---|---|---|
c | Constraint |
- Source
addGlobalNearBehavior(b)
Adds a NearBehavior to all the particles in the world
Name | Type | Description |
---|---|---|
b | NearBehavior |
- Source
addGlobalSelfBehavior(b)
Adds a SelfBehavior to all the particles in the world
Name | Type | Description |
---|---|---|
b | SelfBehavior |
- Source
addParticle(p)
Adds a particle to the world
Name | Type | Description |
---|---|---|
p | Particle |
- Source
addWall(w)
Adds a wall to the world
Name | Type | Description |
---|---|---|
w | Wall |
- Source
clearConstraints()
Clears all of the constraints
- Source
clearParticles()
Clears all of the particles and any associated constraints
- Source
clearWalls()
Clears all of the walls
- Source
constrainBoundary(x1, x2, y1, y2)
Creates a RectangularWorldBoundary
that confines the boundary of the world with rigid collisions. Also sets this.worldConstraint
.
Name | Type | Description |
---|---|---|
x1 | Number | x value of top-left coordinate (smaller) |
x2 | Number | larger x value of bottom-right coordinate (larger) |
y1 | Number | y value of top-left coordinate (smaller) |
y2 | Number | y value of bottom-right coordinate (larger) |
- Source
disableChargeInteractions() → {Boolean}
Removes the global ChargeInteraction behavior and sets this.chargeBehavior
to null
- Source
true if charge behavior is successfully disabled
- Type:
- Boolean
disableCollisions() → {Boolean}
Removes the global gravity behavior and sets this.collision
to null
- Source
true if collision is successfully disabled
- Type:
- Boolean
disableDrag() → {Boolean}
Removes existing drag behavior and sets this.drag
to null
- Source
true if drag is successfully disabled
- Type:
- Boolean
disableGravity() → {Boolean}
Removes the global gravity behavior and sets this.gravity
to null
- Source
true if gravity is successfully disabled
- Type:
- Boolean
enableChargeInteractions()
Removes existing ChargeInteraction behavior and adds a new global ChargeInteraction behavior to all the particles, while updating this.chargeBehavior
- Source
enableCollisions()
Removes existing collision behavior and adds a new global collision behavior to all the particles, while updating this.collision
- Source
enableDrag(viscosity)
Removes existing drag behavior and adds a new global drag behavior with a given viscosity to all the particles, while updating this.drag
Name | Type | Description |
---|---|---|
viscosity | Number |
- Source
enableGravity(num)
Removes existing gravity and adds a new global gravity behavior to all the particles, while updating this.gravity
Name | Type | Description |
---|---|---|
num | Number |
- Source
freePivot(p)
Frees a particle from being a "mass-pivot". This attempts to correct the mass increase from the makePivot()
method. Once again, it may not work properly :skull:.
Name | Type | Description |
---|---|---|
p | Particle |
- Source
true if particle is successfully freed from a "mass-pivot".
makePivot(p, pos) → {Boolean}
Make a particle a "mass-pivot" by adding a PositionLock
behavior and setting the adds Number.MAX_SAFE_INTEGER / 10
to the particle mass. This is a work around and may cause some other physics to break. This particle pivot will not work with position constraints.
- Source
true if particle is successfully converted to a "mass-pivot".
- Type:
- Boolean
nextFrame()
Progresses world to next state
- Source
removeConstraint(c) → {Boolean}
Removes a constraint from the world
Name | Type | Description |
---|---|---|
c | Constraint |
- Source
true if the constraint is removed
- Type:
- Boolean
removeGlobalNearBehavior(b)
Removes a NearBehavior to all the particles in the world
Name | Type | Description |
---|---|---|
b | NearBehavior |
- Source
removeGlobalSelfBehavior(b)
Removes a SelfBehavior from all the particles in the world
Name | Type | Description |
---|---|---|
b | SelfBehavior |
- Source
removeParticle(p)
Removes a particle from the world
Name | Type | Description |
---|---|---|
p | Particle |
- Source
removeWall(w) → {boolean}
Removes a wall from the world
Name | Type | Description |
---|---|---|
w | Wall |
- Source
true if the wall is removed
- Type:
- boolean
setSolverUpdate(update)
Sets the optional update()
function for the solver.
Name | Type | Description |
---|---|---|
update | function |
- Source
updateParticleList()
Update the list of particles. Must be called every time the number of particles change.
- Source