particle

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package particle provides options for generating renderable particle sources.

Index

Constants

View Source
const (

	//IgnoreEnd refers to the life value given to particles that want to skip their source's end function.
	IgnoreEnd = recycled / 2
)

Variables

View Source
var (
	// Inf represents Infinite duration
	Inf = intrange.NewInfinite()
)

Functions

func Allocate

func Allocate(id event.CID) int

Allocate requests a new block in the particle space for the given cid

func And

func And(as ...func(Generator)) func(Generator)

And chains together particle options into a single option for pre-baking option sets

func Angle

func Angle(a floatrange.Range) func(Generator)

Angle sets the initial angle of a particle

func Color

func Color(sc, scr, ec, ecr color.Color) func(Generator)

Color sets colors on a Colorable

func Color2

func Color2(sc, scr, ec, ecr color.Color) func(Generator)

Color2 sets more colors on a Colorable2

func Deallocate

func Deallocate(block int)

Deallocate requests that the given block be removed from the particle space

func Duration

func Duration(i intrange.Range) func(Generator)

Duration sets how long a generator should produce particles for

func End

func End(ef func(Particle)) func(Generator)

End sets what function should happen when a particle dies

func Fragile

func Fragile(f bool) func(*CollisionGenerator)

Fragile sets whether the particles from this collisionGenerator are destroyed on contact

func Gravity

func Gravity(x, y float64) func(Generator)

Gravity sets how a particle should be shifted over time in either dimension

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 Layer

func Layer(l func(physics.Vector) int) func(Generator)

Layer sets a function to determine what draw layer a particle should exist on

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 Pos

func Pos(x, y float64) func(Generator)

Pos sets the position of a generator

func Progress

func Progress(pf func(x, y, w, h int) float64) func(Generator)

Progress sets a Progresses' Progress Function

func Rotation

func Rotation(a floatrange.Range) func(Generator)

Rotation rotates particles by a variable amount per frame

func Shape

func Shape(sf shape.Shape) func(Generator)

Shape is an option to set a generator's shape

func Size

func Size(i intrange.Range) func(Generator)

Size is an option to set a Sizeable size

func Speed

func Speed(s floatrange.Range) func(Generator)

Speed sets the initial speed of a particle

func SpeedDecay

func SpeedDecay(x, y float64) func(Generator)

SpeedDecay sets how the speed of a particle should decay

func Spread

func Spread(x, y float64) func(Generator)

Spread sets how far from a generator's position a particle can spawn

func Sprite

func Sprite(s *render.Sprite) func(Generator)

Sprite sets a Sprited's sprite

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) Cycle

func (bp ColorParticle) Cycle(gen Generator)

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 (bp ColorParticle) GetLayer() int

Need to look at this! This is like the only crash left in oak hopefully

func (*ColorParticle) GetPos

func (cp *ColorParticle) GetPos() physics.Vector

GetPos returns the middle of a color particle

func (ColorParticle) String

func (bp ColorParticle) String() string

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

func NewColorGenerator(options ...func(Generator)) Generator

NewColorGenerator returns a new color generator

func NewGradientGenerator

func NewGradientGenerator(options ...func(Generator)) Generator

NewGradientGenerator returns a new GradientGenerator

func NewSpriteGenerator

func NewSpriteGenerator(options ...func(Generator)) Generator

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) Cycle

func (bp GradientParticle) Cycle(gen Generator)

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

func (GradientParticle) GetLayer

func (bp GradientParticle) GetLayer() int

Need to look at this! This is like the only crash left in oak hopefully

func (GradientParticle) String

func (bp GradientParticle) String() string

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

func Lookup

func Lookup(id int) Particle

Lookup requests a specific particle in the particle space

type Progresses

type Progresses interface {
	SetProgress(func(x, y, w, h int) float64)
}

A Progresses has a SetProgress function where a progress function returns how far between two colors a given coordinate in a space is

type Shapeable

type Shapeable interface {
	SetShape(shape.Shape)
}

Shapeable generators can have the Shape option called on them

type Sizeable

type Sizeable interface {
	SetSize(i intrange.Range)
}

A Sizeable is a generator that can have some size set to it

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

func LookupSource(id int) *Source

LookupSource requests the source bound to a id in a block in the particle space

func NewSource

func NewSource(g Generator, stackLevel int) *Source

NewSource creates a new source

func (*Source) Init

func (ps *Source) Init() event.CID

Init allows a source to be considered as an entity, and initializes it

func (*Source) Layer

func (ps *Source) Layer(v physics.Vector) int

Layer is shorthand for getting the base generator behind a source's layer

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) SetPos

func (ps *Source) SetPos(x, y float64)

SetPos sets a source's underlying generator

func (*Source) ShiftX

func (ps *Source) ShiftX(x float64)

ShiftX shift's a source's underlying generator

func (*Source) ShiftY

func (ps *Source) ShiftY(y float64)

ShiftY shift's a source's underlying generator (todo: consider if this shoud be composed)

func (*Source) Stop

func (ps *Source) Stop()

Stop manually stops a Source, if its duration is infinite or if it should be stopped before expriring naturally.

func (*Source) String

func (ps *Source) String() string

Placeholder

func (*Source) UnPause

func (ps *Source) UnPause()

UnPause on a source a Source rebinds it's rotate function.

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) Cycle

func (bp SpriteParticle) Cycle(gen Generator)

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

func (SpriteParticle) GetDims

func (bp SpriteParticle) GetDims() (int, int)

func (SpriteParticle) GetLayer

func (bp SpriteParticle) GetLayer() int

Need to look at this! This is like the only crash left in oak hopefully

func (SpriteParticle) GetPos

func (bp SpriteParticle) GetPos() physics.Vector

func (SpriteParticle) String

func (bp SpriteParticle) String() string

type Sprited

type Sprited interface {
	SetSprite(*render.Sprite)
	SetSpriteRotation(f floatrange.Range)
}

A Sprited can have a sprite set to it

Jump to

Keyboard shortcuts

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