particle

package
v0.0.0-...-96c78b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 3 Imported by: 2

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

func (p *Particle) ApplyForce(force geo.Vec)

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.

func (*Particle) Update

func (p *Particle) Update(dt time.Duration)

Update causes all applied forces since the last call to Update to take effect on the particle and updates the position based on the, possibly new, velocity. dt is the amount of time to advance.

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

func NewSystem(size int) *System

NewSystem initializes a particle system configured to contain at most size particles.

func (*System) ApplyForce

func (s *System) ApplyForce(force geo.Vec)

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.

func (*System) Update

func (s *System) Update(dt time.Duration)

Update updates the state of all active particles and creates new particles if the limit hasn't been reached yet. dt is the amount of time to simulate.

type SystemParticle

type SystemParticle struct {
	Particle
	Life   time.Duration
	Active bool
	// contains filtered or unexported fields
}

SystemParticle a particle with extra information for use by a System.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL