Packageflare.physics
Classpublic class Simulation

A physical simulation involving particles, springs, and forces. Useful for simulating a range of physical effects or layouts.



Public Properties
 PropertyDefined by
  bounds : Rectangle
Sets a bounding box for particles in this simulation.
Simulation
  dragForce : DragForce
[read-only] The default drag force for this simulation.
Simulation
  gravityForce : GravityForce
[read-only] The default gravity force for this simulation.
Simulation
  nbodyForce : NBodyForce
[read-only] The default n-body force for this simulation.
Simulation
  objectPoolLimit : int = 5000
[static] The maximum number of items stored in a simulation object pool.
Simulation
  particles : Array
[read-only] Returns the particle list.
Simulation
  springForce : SpringForce
[read-only] The default spring force for this simulation.
Simulation
  springs : Array
[read-only] Returns the spring list.
Simulation
Protected Properties
 PropertyDefined by
  _ppool : Array
[static]
Simulation
  _spool : Array
[static]
Simulation
Public Methods
 MethodDefined by
  
Simulation(gx:Number = 0, gy:Number = 0, drag:Number = 0.1, attraction:Number = -5)
Creates a new physics simulation.
Simulation
  
addForce(force:IForce):void
Adds a custom force to the force simulation.
Simulation
  
addParticle(mass:Number, x:Number, y:Number):Particle
Adds a new particle to the simulation.
Simulation
  
addSpring(p1:Particle, p2:Particle, restLength:Number, tension:Number, damping:Number):Spring
Adds a spring to the simulation
Simulation
  
eval():void
Evaluates the set of forces in the simulation.
Simulation
  
getForceAt(idx:int):IForce
Returns the force at the given index.
Simulation
  
removeParticle(idx:uint):Boolean
Removes a particle from the simulation.
Simulation
  
removeSpring(idx:uint):Boolean
Removes a spring from the simulation.
Simulation
  
tick(dt:Number = 1):void
Advance the simulation for the specified time interval.
Simulation
Protected Methods
 MethodDefined by
  
getParticle(mass:Number, x:Number, y:Number):Particle
[static] Returns a particle instance, pulling a recycled particle from the object pool if available.
Simulation
  
getSpring(p1:Particle, p2:Particle, restLength:Number, tension:Number, damping:Number):Spring
[static] Returns a spring instance, pulling a recycled spring from the object pool if available.
Simulation
  
[static] Reclaims a particle, adding it to the object pool for recycling
Simulation
  
[static] Reclaims a spring, adding it to the object pool for recycling
Simulation
Property detail
boundsproperty
bounds:Rectangle  [read-write]

Sets a bounding box for particles in this simulation. Null (the default) indicates no boundaries.

Implementation
    public function get bounds():Rectangle
    public function set bounds(value:Rectangle):void
dragForceproperty 
dragForce:DragForce  [read-only]

The default drag force for this simulation.

Implementation
    public function get dragForce():DragForce
gravityForceproperty 
gravityForce:GravityForce  [read-only]

The default gravity force for this simulation.

Implementation
    public function get gravityForce():GravityForce
nbodyForceproperty 
nbodyForce:NBodyForce  [read-only]

The default n-body force for this simulation.

Implementation
    public function get nbodyForce():NBodyForce
objectPoolLimitproperty 
public static var objectPoolLimit:int = 5000

The maximum number of items stored in a simulation object pool.

particlesproperty 
particles:Array  [read-only]

Returns the particle list. This is the same array instance backing the simulation, so edit the array with caution.

Implementation
    public function get particles():Array
_ppoolproperty 
protected static var _ppool:Array
_spoolproperty 
protected static var _spool:Array
springForceproperty 
springForce:SpringForce  [read-only]

The default spring force for this simulation.

Implementation
    public function get springForce():SpringForce
springsproperty 
springs:Array  [read-only]

Returns the spring list. This is the same array instance backing the simulation, so edit the array with caution.

Implementation
    public function get springs():Array
Constructor detail
Simulation()constructor
public function Simulation(gx:Number = 0, gy:Number = 0, drag:Number = 0.1, attraction:Number = -5)

Creates a new physics simulation.

Parameters
gx:Number (default = 0) — the gravitational acceleration along the x dimension
 
gy:Number (default = 0) — the gravitational acceleration along the y dimension
 
drag:Number (default = 0.1) — the default drag (viscosity) co-efficient
 
attraction:Number (default = -5) — the gravitational attraction (or repulsion, for negative values) between particles.
Method detail
addForce()method
public function addForce(force:IForce):void

Adds a custom force to the force simulation.

Parameters
force:IForce — the force to add
addParticle()method 
public function addParticle(mass:Number, x:Number, y:Number):Particle

Adds a new particle to the simulation.

Parameters
mass:Number — the mass (charge) of the particle
 
x:Number — the particle's starting x position
 
y:Number — the particle's starting y position

Returns
Particle — the added particle
addSpring()method 
public function addSpring(p1:Particle, p2:Particle, restLength:Number, tension:Number, damping:Number):Spring

Adds a spring to the simulation

Parameters
p1:Particle — the first particle attached to the spring
 
p2:Particle — the second particle attached to the spring
 
restLength:Number — the rest length of the spring
 
tension:Number — the tension of the spring
 
damping:Number — the damping (friction) co-efficient of the spring

Returns
Spring — the added spring
eval()method 
public function eval():void

Evaluates the set of forces in the simulation.

getForceAt()method 
public function getForceAt(idx:int):IForce

Returns the force at the given index.

Parameters
idx:int — the index of the force to look up

Returns
IForce — the force at the specified index
getParticle()method 
protected static function getParticle(mass:Number, x:Number, y:Number):Particle

Returns a particle instance, pulling a recycled particle from the object pool if available.

Parameters
mass:Number — the mass (charge) of the particle
 
x:Number — the particle's starting x position
 
y:Number — the particle's starting y position

Returns
Particle — a particle instance
getSpring()method 
protected static function getSpring(p1:Particle, p2:Particle, restLength:Number, tension:Number, damping:Number):Spring

Returns a spring instance, pulling a recycled spring from the object pool if available.

Parameters
p1:Particle — the first particle attached to the spring
 
p2:Particle — the second particle attached to the spring
 
restLength:Number — the rest length of the spring
 
tension:Number — the tension of the spring
 
damping:Number — the damping (friction) co-efficient of the spring

Returns
Spring — a spring instance
reclaimParticle()method 
protected static function reclaimParticle(p:Particle):void

Reclaims a particle, adding it to the object pool for recycling

Parameters
p:Particle — the particle to reclaim
reclaimSpring()method 
protected static function reclaimSpring(s:Spring):void

Reclaims a spring, adding it to the object pool for recycling

Parameters
s:Spring — the spring to reclaim
removeParticle()method 
public function removeParticle(idx:uint):Boolean

Removes a particle from the simulation. Any springs attached to the particle will also be removed.

Parameters
idx:uint — the index of the particle in the particle list

Returns
Boolean — true if removed, false otherwise.
removeSpring()method 
public function removeSpring(idx:uint):Boolean

Removes a spring from the simulation.

Parameters
idx:uint — the index of the spring in the spring list

Returns
Boolean — true if removed, false otherwise
tick()method 
public function tick(dt:Number = 1):void

Advance the simulation for the specified time interval.

Parameters
dt:Number (default = 1) — the time interval to step the simulation (default 1)