Documentation ¶
Overview ¶
Package particle provides options for generating renderable particle sources.
Index ¶
- Constants
- Variables
- func Allocate(id event.CID) int
- func And(as ...func(Generator)) func(Generator)
- func Angle(a floatrange.Range) func(Generator)
- func Color(sc, scr, ec, ecr color.Color) func(Generator)
- func Color2(sc, scr, ec, ecr color.Color) func(Generator)
- func Deallocate(block int)
- func Duration(i intrange.Range) func(Generator)
- func End(ef func(Particle)) func(Generator)
- func Fragile(f bool) func(*CollisionGenerator)
- func Gravity(x, y float64) func(Generator)
- func HitMap(hm map[collision.Label]collision.OnHit) func(*CollisionGenerator)
- func Layer(l func(physics.Vector) int) func(Generator)
- func LifeSpan(ls floatrange.Range) func(Generator)
- func NewPerFrame(npf floatrange.Range) func(Generator)
- func Pos(x, y float64) func(Generator)
- func Progress(pf func(x, y, w, h int) float64) func(Generator)
- func Rotation(a floatrange.Range) func(Generator)
- func Shape(sf shape.Shape) func(Generator)
- func Size(i intrange.Range) func(Generator)
- func Speed(s floatrange.Range) func(Generator)
- func SpeedDecay(x, y float64) func(Generator)
- func Spread(x, y float64) func(Generator)
- func Sprite(s *render.Sprite) func(Generator)
- func SpriteRotation(f floatrange.Range) func(Generator)
- type BaseGenerator
- type CollisionGenerator
- type CollisionParticle
- func (cp *CollisionParticle) Cycle(generator Generator)
- func (cp *CollisionParticle) Draw(buff draw.Image)
- func (cp *CollisionParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (cp *CollisionParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
- func (cp *CollisionParticle) GetDims() (int, int)
- func (cp *CollisionParticle) String() string
- type ColorGenerator
- func (cg *ColorGenerator) Generate(layer int) *Source
- func (cg *ColorGenerator) GenerateParticle(bp *baseParticle) Particle
- func (cg *ColorGenerator) GetParticleSize() (float64, float64, bool)
- func (cg *ColorGenerator) SetEndColor(ec, ecr color.Color)
- func (cg *ColorGenerator) SetShape(sf shape.Shape)
- func (cg *ColorGenerator) SetSize(i intrange.Range)
- func (cg *ColorGenerator) SetStartColor(sc, scr color.Color)
- type ColorParticle
- func (bp ColorParticle) Cycle(gen Generator)
- func (cp *ColorParticle) Draw(buff draw.Image)
- func (cp *ColorParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (cp *ColorParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
- func (bp ColorParticle) GetBaseParticle() *baseParticle
- func (cp *ColorParticle) GetDims() (int, int)
- func (cp *ColorParticle) GetLayer() int
- func (cp *ColorParticle) GetPos() physics.Vector
- func (bp ColorParticle) String() string
- type Colorable
- type Colorable2
- type Generator
- type GradientGenerator
- func (gg *GradientGenerator) Generate(layer int) *Source
- func (gg *GradientGenerator) GenerateParticle(bp *baseParticle) Particle
- func (gg *GradientGenerator) SetEndColor2(ec, ecr color.Color)
- func (gg *GradientGenerator) SetProgress(pf func(x, y, w, h int) float64)
- func (gg *GradientGenerator) SetStartColor2(sc, scr color.Color)
- type GradientParticle
- func (bp GradientParticle) Cycle(gen Generator)
- func (gp *GradientParticle) Draw(buff draw.Image)
- func (gp *GradientParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (gp *GradientParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
- func (bp GradientParticle) GetBaseParticle() *baseParticle
- func (bp GradientParticle) String() string
- type Particle
- type Progresses
- type Shapeable
- type Sizeable
- type Source
- func (ps *Source) Init() event.CID
- func (ps *Source) Layer(v physics.Vector) int
- func (ps *Source) Pause()
- func (ps *Source) SetPos(x, y float64)
- func (ps *Source) ShiftX(x float64)
- func (ps *Source) ShiftY(y float64)
- func (ps *Source) Stop()
- func (ps *Source) String() string
- func (ps *Source) UnPause()
- type SpriteGenerator
- func (sg *SpriteGenerator) Generate(layer int) *Source
- func (sg *SpriteGenerator) GenerateParticle(bp *baseParticle) Particle
- func (sg *SpriteGenerator) GetParticleSize() (float64, float64, bool)
- func (sg *SpriteGenerator) SetSprite(s *render.Sprite)
- func (sg *SpriteGenerator) SetSpriteRotation(f floatrange.Range)
- type SpriteParticle
- func (bp SpriteParticle) Cycle(gen Generator)
- func (sp *SpriteParticle) Draw(buff draw.Image)
- func (sp *SpriteParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
- func (sp *SpriteParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
- func (bp SpriteParticle) GetBaseParticle() *baseParticle
- func (bp SpriteParticle) GetDims() (int, int)
- func (bp SpriteParticle) GetLayer() int
- func (bp SpriteParticle) GetPos() physics.Vector
- func (bp SpriteParticle) String() string
- type Sprited
Constants ¶
const (
//IgnoreEnd refers to the life value given to particles that want to skip their source's end function.
IgnoreEnd = recycled / 2
)
Variables ¶
var ( // Inf represents Infinite duration Inf = intrange.NewInfinite() )
Functions ¶
func Angle ¶
func Angle(a floatrange.Range) func(Generator)
Angle sets the initial angle of a particle
func Deallocate ¶
func Deallocate(block int)
Deallocate requests that the given block be removed from the particle space
func Fragile ¶
func Fragile(f bool) func(*CollisionGenerator)
Fragile sets whether the particles from this collisionGenerator are destroyed on contact
func HitMap ¶
func HitMap(hm map[collision.Label]collision.OnHit) func(*CollisionGenerator)
HitMap sets functions to be called when particles from this generator collide with other spaces
func LifeSpan ¶
func LifeSpan(ls floatrange.Range) func(Generator)
LifeSpan sets how long a particle should last before dying
func NewPerFrame ¶
func NewPerFrame(npf floatrange.Range) func(Generator)
NewPerFrame sets how many particles should be produced per frame
func Rotation ¶
func Rotation(a floatrange.Range) func(Generator)
Rotation rotates particles by a variable amount per frame
func Speed ¶
func Speed(s floatrange.Range) func(Generator)
Speed sets the initial speed of a particle
func SpeedDecay ¶
SpeedDecay sets how the speed of a particle should decay
func SpriteRotation ¶
func SpriteRotation(f floatrange.Range) func(Generator)
SpriteRotation sets a Sprited's rotation
Types ¶
type BaseGenerator ¶
type BaseGenerator struct { physics.Vector // This float is currently forced to an integer // at new particle rotation. This should be changed // to something along the lines of 'new per 30 frames', // or allow low fractional values to be meaningful, // so that more fine-tuned particle generation speeds are possible. NewPerFrame floatrange.Range // The number of frames each particle should persist // before being removed. LifeSpan floatrange.Range // 0 - between quadrant 1 and 4 // 90 - between quadrant 2 and 1 Angle floatrange.Range Speed floatrange.Range Spread physics.Vector // Duration in milliseconds for the particle source. // After this many milliseconds have passed, it will // stop sending out new particles. Old particles will // not be removed until their individual lifespans run // out. // A duration of -1 represents never stopping. Duration intrange.Range // Rotational acceleration, to change angle over time Rotation floatrange.Range // Gravity X() and Gravity Y() represent particle acceleration per frame. Gravity physics.Vector SpeedDecay physics.Vector EndFunc func(Particle) LayerFunc func(physics.Vector) int }
A BaseGenerator fulfills all basic requirements to generate particles Modeled after Parcycle
func (*BaseGenerator) GetBaseGenerator ¶
func (bg *BaseGenerator) GetBaseGenerator() *BaseGenerator
GetBaseGenerator returns this
func (*BaseGenerator) SetPos ¶
func (bg *BaseGenerator) SetPos(x, y float64)
SetPos sets the position of a base generator
func (*BaseGenerator) ShiftX ¶
func (bg *BaseGenerator) ShiftX(x float64)
ShiftX moves a base generator by an x value
func (*BaseGenerator) ShiftY ¶
func (bg *BaseGenerator) ShiftY(y float64)
ShiftY moves a base generator by a y value
type CollisionGenerator ¶
type CollisionGenerator struct { Generator Fragile bool HitMap map[collision.Label]collision.OnHit }
A CollisionGenerator generates collision particles
func (*CollisionGenerator) Generate ¶
func (cg *CollisionGenerator) Generate(layer int) *Source
Generate creates a source using this generator
func (*CollisionGenerator) GenerateParticle ¶
func (cg *CollisionGenerator) GenerateParticle(bp *baseParticle) Particle
GenerateParticle creates a particle from a generator
func (*CollisionGenerator) GetParticleSize ¶
func (cg *CollisionGenerator) GetParticleSize() (float64, float64, bool)
GetParticleSize on a CollisionGenerator tells the caller that the particle size is per-particle specific
type CollisionParticle ¶
type CollisionParticle struct { Particle // contains filtered or unexported fields }
A CollisionParticle is a wrapper around other particles that also has a collision space and can functionally react with the environment on collision
func (*CollisionParticle) Cycle ¶
func (cp *CollisionParticle) Cycle(generator Generator)
Cycle updates the collisiion particles variables once per rotation
func (*CollisionParticle) Draw ¶
func (cp *CollisionParticle) Draw(buff draw.Image)
Draw redirectes to DrawOffset
func (*CollisionParticle) DrawOffset ¶
func (cp *CollisionParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
DrawOffset redirectes to DrawOffsetGen
func (*CollisionParticle) DrawOffsetGen ¶
func (cp *CollisionParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
DrawOffsetGen draws a particle with it's generator's variables
func (*CollisionParticle) GetDims ¶
func (cp *CollisionParticle) GetDims() (int, int)
GetDims returns the dimensions of the space of the particle
func (*CollisionParticle) String ¶
func (cp *CollisionParticle) String() string
String returns the type as string
type ColorGenerator ¶
type ColorGenerator struct { BaseGenerator StartColor, StartColorRand color.Color EndColor, EndColorRand color.Color // The size, in pixel radius, of spawned particles Size intrange.Range // // Some sort of particle type, for rendering triangles or squares or circles... Shape shape.Shape }
A ColorGenerator generates ColorParticles
func (*ColorGenerator) Generate ¶
func (cg *ColorGenerator) Generate(layer int) *Source
Generate creates a source using this generator
func (*ColorGenerator) GenerateParticle ¶
func (cg *ColorGenerator) GenerateParticle(bp *baseParticle) Particle
GenerateParticle creates a particle from a generator
func (*ColorGenerator) GetParticleSize ¶
func (cg *ColorGenerator) GetParticleSize() (float64, float64, bool)
GetParticleSize on a color generator returns that the particles are per-particle specificially sized
func (*ColorGenerator) SetEndColor ¶
func (cg *ColorGenerator) SetEndColor(ec, ecr color.Color)
SetEndColor lets cg have its end color be set
func (*ColorGenerator) SetShape ¶
func (cg *ColorGenerator) SetShape(sf shape.Shape)
SetShape satisfies Shapeable
func (*ColorGenerator) SetSize ¶
func (cg *ColorGenerator) SetSize(i intrange.Range)
SetSize satisfies Sizeable
func (*ColorGenerator) SetStartColor ¶
func (cg *ColorGenerator) SetStartColor(sc, scr color.Color)
SetStartColor lets cg have its color be set
type ColorParticle ¶
type ColorParticle struct {
// contains filtered or unexported fields
}
A ColorParticle is a particle with a defined color and size
func (*ColorParticle) Draw ¶
func (cp *ColorParticle) Draw(buff draw.Image)
Draw redirectes to DrawOffset
func (*ColorParticle) DrawOffset ¶
func (cp *ColorParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
DrawOffset redirectes to DrawOffsetGen
func (*ColorParticle) DrawOffsetGen ¶
func (cp *ColorParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
DrawOffsetGen draws a particle with it's generator's variables
func (ColorParticle) GetBaseParticle ¶
func (bp ColorParticle) GetBaseParticle() *baseParticle
func (*ColorParticle) GetDims ¶
func (cp *ColorParticle) GetDims() (int, int)
GetDims returns the color particle's size, twice
func (*ColorParticle) GetLayer ¶
func (cp *ColorParticle) GetLayer() int
GetLayer returns baseParticle GetLayer. This is a safety check against auto-generated code which would not contain the nil check here
func (*ColorParticle) GetPos ¶
func (cp *ColorParticle) GetPos() physics.Vector
GetPos returns the middle of a color particle
type Colorable ¶
type Colorable interface { SetStartColor(color.Color, color.Color) SetEndColor(color.Color, color.Color) }
A Colorable can have colors set on it.
type Colorable2 ¶
type Colorable2 interface { SetStartColor2(color.Color, color.Color) SetEndColor2(color.Color, color.Color) }
A Colorable2 can have more colors set on it
type Generator ¶
type Generator interface { GetBaseGenerator() *BaseGenerator GenerateParticle(*baseParticle) Particle Generate(int) *Source GetParticleSize() (float64, float64, bool) ShiftX(float64) ShiftY(float64) SetPos(float64, float64) GetPos() (float64, float64) }
A Generator holds settings for generating particles
func NewCollisionGenerator ¶
func NewCollisionGenerator(g Generator, options ...func(*CollisionGenerator)) Generator
NewCollisionGenerator creates a new collision generator
func NewColorGenerator ¶
NewColorGenerator returns a new color generator
func NewGradientGenerator ¶
NewGradientGenerator returns a new GradientGenerator
func NewSpriteGenerator ¶
NewSpriteGenerator creates a SpriteGenerator
type GradientGenerator ¶
type GradientGenerator struct { ColorGenerator StartColor2, StartColor2Rand color.Color EndColor2, EndColor2Rand color.Color ProgressFunction func(x, y, w, h int) float64 }
A GradientGenerator is a ColorGenerator with a patterned gradient on its particles
func (*GradientGenerator) Generate ¶
func (gg *GradientGenerator) Generate(layer int) *Source
Generate takes a generator and converts it into a source, drawing particles and binding functions for particle generation and rotation.
func (*GradientGenerator) GenerateParticle ¶
func (gg *GradientGenerator) GenerateParticle(bp *baseParticle) Particle
GenerateParticle creates a particle from a generator
func (*GradientGenerator) SetEndColor2 ¶
func (gg *GradientGenerator) SetEndColor2(ec, ecr color.Color)
SetEndColor2 satisfies Colorable2
func (*GradientGenerator) SetProgress ¶
func (gg *GradientGenerator) SetProgress(pf func(x, y, w, h int) float64)
SetProgress satisfies Progresses
func (*GradientGenerator) SetStartColor2 ¶
func (gg *GradientGenerator) SetStartColor2(sc, scr color.Color)
SetStartColor2 satisfies Colorable2
type GradientParticle ¶
type GradientParticle struct { ColorParticle // contains filtered or unexported fields }
A GradientParticle has a gradient from one color to another
func (*GradientParticle) Draw ¶
func (gp *GradientParticle) Draw(buff draw.Image)
Draw redirectes to DrawOffset
func (*GradientParticle) DrawOffset ¶
func (gp *GradientParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
DrawOffset redirectes to DrawOffsetGen
func (*GradientParticle) DrawOffsetGen ¶
func (gp *GradientParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
DrawOffsetGen draws a particle with it's generator's variables
func (GradientParticle) GetBaseParticle ¶
func (bp GradientParticle) GetBaseParticle() *baseParticle
type Particle ¶
type Particle interface { render.Renderable GetBaseParticle() *baseParticle GetPos() physics.Vector DrawOffsetGen(gen Generator, buff draw.Image, xOff, yOff float64) Cycle(gen Generator) }
A Particle is a renderable that is spawned by a generator, usually very fast, usually very small, for visual effects
type Progresses ¶
A Progresses has a SetProgress function where a progress function returns how far between two colors a given coordinate in a space is
type Source ¶
type Source struct { render.Layered Generator Generator CID event.CID EndFunc func() // contains filtered or unexported fields }
A Source is used to store and control a set of particles.
func LookupSource ¶
LookupSource requests the source that generated a pid
func (*Source) Pause ¶
func (ps *Source) Pause()
Pause on a Source just stops the repetition of its rotation function, which moves, destroys, ages and generates particles. Existing particles will stay in place.
func (*Source) ShiftY ¶
ShiftY shift's a source's underlying generator (todo: consider if this shoud be composed)
type SpriteGenerator ¶
type SpriteGenerator struct { BaseGenerator SpriteRotation floatrange.Range Base *render.Sprite }
A SpriteGenerator generate SpriteParticles
func (*SpriteGenerator) Generate ¶
func (sg *SpriteGenerator) Generate(layer int) *Source
Generate creates a source using this generator
func (*SpriteGenerator) GenerateParticle ¶
func (sg *SpriteGenerator) GenerateParticle(bp *baseParticle) Particle
GenerateParticle creates a particle from a generator
func (*SpriteGenerator) GetParticleSize ¶
func (sg *SpriteGenerator) GetParticleSize() (float64, float64, bool)
GetParticleSize returns the size of the sprite that the generator generates
func (*SpriteGenerator) SetSprite ¶
func (sg *SpriteGenerator) SetSprite(s *render.Sprite)
SetSprite is the function on a sprite generator that satisfies Sprited
func (*SpriteGenerator) SetSpriteRotation ¶
func (sg *SpriteGenerator) SetSpriteRotation(f floatrange.Range)
SetSpriteRotation satisfied Sprited for SpriteGenerators
type SpriteParticle ¶
type SpriteParticle struct {
// contains filtered or unexported fields
}
A SpriteParticle is a particle that has an amount of sprite rotation
func (*SpriteParticle) Draw ¶
func (sp *SpriteParticle) Draw(buff draw.Image)
Draw redirectes to DrawOffset
func (*SpriteParticle) DrawOffset ¶
func (sp *SpriteParticle) DrawOffset(buff draw.Image, xOff, yOff float64)
DrawOffset redirects to DrawOffsetGen
func (*SpriteParticle) DrawOffsetGen ¶
func (sp *SpriteParticle) DrawOffsetGen(generator Generator, buff draw.Image, xOff, yOff float64)
DrawOffsetGen draws a particle with it's generator's variables
func (SpriteParticle) GetBaseParticle ¶
func (bp SpriteParticle) GetBaseParticle() *baseParticle