Documentation ¶
Overview ¶
Package particle provides options for generating renderable particle sources.
Package particle provides options for generating renderable particle sources.
Index ¶
- Constants
- Variables
- func And(as ...func(Generator)) func(Generator)
- func Angle(a span.Span[float64]) func(Generator)
- func Color(start, startRand, end, endRand color.Color) func(Generator)
- func Color2(start, startRand, end, endRand color.Color) func(Generator)
- func DrawStack(drawStack *render.DrawStack) func(Generator)
- func Duration(i span.Span[int]) func(Generator)
- func End(ef func(Particle)) func(Generator)
- func EndSize(i span.Span[int]) 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 InfiniteLifeSpan() func(Generator)
- func Layer(l func(physics.Vector) int) func(Generator)
- func LifeSpan(ls span.Span[float64]) func(Generator)
- func Limit(limit int) func(Generator)
- func NewPerFrame(npf span.Span[float64]) func(Generator)
- func Pos(x, y float64) func(Generator)
- func Progress(pf func(x, y, w, h int) float64) func(Generator)
- func Rotation(a span.Span[float64]) func(Generator)
- func Shape(sf shape.Shape) func(Generator)
- func Size(i span.Span[int]) func(Generator)
- func Speed(s span.Span[float64]) 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 span.Span[float64]) func(Generator)
- type Allocator
- type BaseGenerator
- type CollisionGenerator
- type CollisionParticle
- type ColorGenerator
- func (cg *ColorGenerator) Generate(layer int) *Source
- func (cg *ColorGenerator) GenerateParticle(bp *baseParticle) Particle
- func (cg *ColorGenerator) GetParticleSize() (w float64, h float64, perParticle bool)
- func (cg *ColorGenerator) SetEndColor(ec, ecr color.Color)
- func (cg *ColorGenerator) SetEndSize(i span.Span[int])
- func (cg *ColorGenerator) SetShape(sf shape.Shape)
- func (cg *ColorGenerator) SetSize(i span.Span[int])
- func (cg *ColorGenerator) SetStartColor(sc, scr color.Color)
- type ColorParticle
- func (bp ColorParticle) Cycle(gen Generator)
- func (cp *ColorParticle) Draw(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
- 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
- type Particle
- type Progresses
- type Shapeable
- type Sizeable
- type Source
- func (ps *Source) CID() event.CallerID
- func (ps *Source) IsPaused() bool
- 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) UnPause()
- type SpriteGenerator
- func (sg *SpriteGenerator) Generate(layer int) *Source
- func (sg *SpriteGenerator) GenerateParticle(bp *baseParticle) Particle
- func (sg *SpriteGenerator) GetParticleSize() (w float64, h float64, perParticle bool)
- func (sg *SpriteGenerator) SetSprite(s *render.Sprite)
- func (sg *SpriteGenerator) SetSpriteRotation(f span.Span[float64])
- type SpriteParticle
- func (bp SpriteParticle) Cycle(gen Generator)
- func (sp *SpriteParticle) Draw(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
- type Sprited
Constants ¶
const (
//IgnoreEnd refers to the life value given to particles that want to skip their source's end function.
IgnoreEnd = -2000 / 2
)
Variables ¶
var DefaultAllocator = NewAllocator()
DefaultAllocator is an allocator that starts running as soon as this package is imported.
var ( // Inf represents Infinite duration Inf = span.NewConstant(math.MaxInt32) )
Functions ¶
func DrawStack ¶ added in v4.1.0
DrawStack sets the current drawstack so that we dont use the globaldrawstack
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 InfiniteLifeSpan ¶
func InfiniteLifeSpan() func(Generator)
InfiniteLifeSpan will set particles to never die over time.
func Limit ¶
Limit limits the total number of particles a particle generator can have active at once.
func NewPerFrame ¶
NewPerFrame sets how many particles should be produced per frame
func SpeedDecay ¶
SpeedDecay sets how the speed of a particle should decay
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
An Allocator can allocate ids for particles
func (*Allocator) Deallocate ¶
Deallocate requests that the given block be removed from the particle space
func (*Allocator) LookupSource ¶
LookupSource requests the source that generated a pid
type BaseGenerator ¶
type BaseGenerator struct { physics.Vector DrawStack *render.DrawStack // 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 span.Span[float64] // The number of frames each particle should persist // before being removed. LifeSpan span.Span[float64] // 0 - between quadrant 1 and 4 // 90 - between quadrant 2 and 1 Angle span.Span[float64] Speed span.Span[float64] 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 span.Span[int] // Rotational acceleration, to change angle over time Rotation span.Span[float64] // Gravity X() and Gravity Y() represent particle acceleration per frame. Gravity physics.Vector SpeedDecay physics.Vector EndFunc func(Particle) LayerFunc func(physics.Vector) int ParticleLimit 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() (w float64, h float64, perParticle 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 collision particles variables once per rotation
func (*CollisionParticle) Draw ¶
func (cp *CollisionParticle) Draw(buff draw.Image, xOff, yOff float64)
Draw redirects 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
type ColorGenerator ¶
type ColorGenerator struct { BaseGenerator StartColor, StartColorRand color.Color EndColor, EndColorRand color.Color // The size, in pixel radius, of spawned particles Size span.Span[int] EndSize span.Span[int] // // 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() (w float64, h float64, perParticle bool)
GetParticleSize on a color generator returns that the particles are per-particle specifically sized
func (*ColorGenerator) SetEndColor ¶
func (cg *ColorGenerator) SetEndColor(ec, ecr color.Color)
SetEndColor lets cg have its end color be set
func (*ColorGenerator) SetEndSize ¶
func (cg *ColorGenerator) SetEndSize(i span.Span[int])
SetEndSize stasfies Sizeable
func (*ColorGenerator) SetShape ¶
func (cg *ColorGenerator) SetShape(sf shape.Shape)
SetShape satisfies Shapeable
func (*ColorGenerator) SetSize ¶
func (cg *ColorGenerator) SetSize(i span.Span[int])
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, xOff, yOff float64)
Draw redirects 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 with some applied options.
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, xOff, yOff float64)
Draw redirects 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) // contains filtered or unexported methods }
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 { Generator Generator *Allocator event.CallerID EndFunc func() // contains filtered or unexported fields }
A Source is used to store and control a set of particles.
func NewDefaultSource ¶
NewDefaultSource creates a new sourceattached to the default event bus.
func NewSource ¶
NewSource for particles constructed from a generator with specifications on how the particles should be handled.
func (*Source) IsPaused ¶
IsPaused checks for whether the source is currently in a paused state. It probably would have made more sense to export paused but this way if a lock is needed here in the future... Then it wont change the api.
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.
type SpriteGenerator ¶
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() (w float64, h float64, perParticle 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 span.Span[float64])
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, xOff, yOff float64)
Draw 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