Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Particle ¶
type Particle struct { // Pos is the position of the particle. No particular units are assumed. Pos geo.Vec // Vel is the velocity of the particle. It is the number units per second Pos changes // on a call to Update. Vel geo.Vec // A Mass of 0 will ignore applied forces. Mass float64 // contains filtered or unexported fields }
Particle is a generatic particle that has a position and velocity. It also allows forces to be applied to it.
func (*Particle) ApplyForce ¶
ApplyForce applies the given force to the particle taking its Mass into account. It will not affect the particle until Update is called. If multiple forces are applied then they will accumulate. Forces will not persist between calls to Update.
type System ¶
type System struct { // Rate is the number of new particles per second. Rate float64 // InitPos/Vel/Mass/Life are the starting parameters for each new particle. InitPos geo.VecGen InitVel geo.VecGen InitMass geo.NumGen InitLife time.Duration // contains filtered or unexported fields }
System is a manager for large groups of particles.
func NewSystem ¶
NewSystem initializes a particle system configured to contain at most size particles.
func (*System) ApplyForce ¶
ApplyForce applies a force to each particle. Forces are cleared after each call to Update. If you want to do something like a drag force, where it's different for each particle, then that could be done by applying the force to each particle before calling Update.
system.ForEachParticle(func(p *SystemParticle) { force := <calculate force> p.ApplyForce(force) }) system.Update()
func (*System) ForEachParticle ¶
func (s *System) ForEachParticle(f func(p *SystemParticle))
ForEachParticle calls f for each active particle.
func (*System) Particles ¶
func (s *System) Particles() []*SystemParticle
Particles returns a slice of all active particles.