dust

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dust is a particle simulator

Package dust is a particle simulator

Package dust is a particle simulator

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomConfig

func RandomConfig(d *Dust)

RandomConfig is a config that give a new particle a random velocity.

Types

type Bin

type Bin struct {
	List []*Dust
	// contains filtered or unexported fields
}

Bin is a list of particles.

func NewBin

func NewBin() *Bin

NewBin creates a new Bin.

func NewBinFromPointList

func NewBinFromPointList(list geom.PointList) *Bin

NewBinFromPointList creates a bin of particles based on a point list.

func (*Bin) Add

func (b *Bin) Add(d *Dust)

Add adds a particle to this bin.

func (*Bin) AddPoint

func (b *Bin) AddPoint(p *geom.Point)

AddPoint adds a particle to this bin based on a point.

func (*Bin) AddPoints

func (b *Bin) AddPoints(points geom.PointList)

AddPoints adds all the points in this list to the bin.

func (*Bin) AddXY

func (b *Bin) AddXY(x, y float64)

AddXY adds a particle to this bin, using only x, y coords.

func (*Bin) Bounce

func (b *Bin) Bounce(x, y, w, h float64)

Bounce bounces the points off each edge of the space defined by the params.

func (*Bin) BounceCircle

func (b *Bin) BounceCircle(x, y, radius, bounce float64)

BounceCircle causes all particles in this bin to bounce off the specified circle.

func (*Bin) Count

func (b *Bin) Count() int

Count returns the number of particles in this bin.

func (*Bin) Cull

func (b *Bin) Cull(x, y, w, h float64)

Cull removes any points that go outside of the space defined by the params.

func (*Bin) CullByAge

func (b *Bin) CullByAge(age int)

CullByAge removes any points that have been updated more than a given number of times.

func (*Bin) Fade

func (b *Bin) Fade(age, fadeTime int)

Fade removes any points that have been updated more than a given number of times.

func (*Bin) First

func (b *Bin) First() *Dust

First returns the first particle in the bin.

func (*Bin) Get

func (b *Bin) Get(i int) *Dust

Get returns the particle at the given index.

func (*Bin) GravitateTo

func (b *Bin) GravitateTo(x, y, gravity float64)

GravitateTo pulls all the particles in this bin to the given x, y point.

func (*Bin) GravitateToDust

func (b *Bin) GravitateToDust(part *Dust, gravity float64)

GravitateToDust pulls all the particles in this bin to the given dust particle.

func (*Bin) GravitateToPoint

func (b *Bin) GravitateToPoint(point *geom.Point, gravity float64)

GravitateToPoint pulls all the particles in this bin to the given point.

func (*Bin) Gravity

func (b *Bin) Gravity(g float64)

Gravity adds gravity to each particle, pulling it downwards.

func (*Bin) Last

func (b *Bin) Last() *Dust

Last returns the last particle in the bin.

func (*Bin) Points

func (b *Bin) Points() geom.PointList

Points returns this Bin as a list of points.

func (*Bin) RandomizeVelocity

func (b *Bin) RandomizeVelocity(min, max float64)

RandomizeVelocity randomizes the velocity of all particles in this bin.

func (*Bin) Remove

func (b *Bin) Remove(d *Dust)

Remove removes the given dust particle from the bin.

func (*Bin) RepelFrom

func (b *Bin) RepelFrom(x, y, radius, k float64)

RepelFrom repels all the particles in this bin from the given x, y point to the given radius.

func (*Bin) SetBounce

func (b *Bin) SetBounce(bounce float64)

SetBounce sets the bounce value for all particles in this bin.

func (*Bin) SetDamp

func (b *Bin) SetDamp(damp float64)

SetDamp sets the damp value for all particles in this bin.

func (*Bin) SetMaxVelocity

func (b *Bin) SetMaxVelocity(vel float64)

SetMaxVelocity sets the maximum velocity for all particles in this bin.

func (*Bin) SpringTo

func (b *Bin) SpringTo(x, y, k float64)

SpringTo springs all the particles in this bin to the given x, y point.

func (*Bin) SpringToDust

func (b *Bin) SpringToDust(part *Dust, k float64)

SpringToDust springs all the particles in this bin to the given dust particle.

func (*Bin) SpringToPoint

func (b *Bin) SpringToPoint(point *geom.Point, k float64)

SpringToPoint springs all the particles in this bin to the given point.

func (*Bin) SpringToRadius

func (b *Bin) SpringToRadius(x, y, radius, k float64)

SpringToRadius springs all particles to a distance away from the given x, y point.

func (*Bin) Update

func (b *Bin) Update()

Update updates all the particles in this bin.

func (*Bin) Wander

func (b *Bin) Wander(w float64)

Wander makes all the particles in this bin wander around.

func (*Bin) Wrap

func (b *Bin) Wrap(x, y, w, h float64)

Wrap wraps the points around the space defined by the params.

type ConfigFunc

type ConfigFunc func(d *Dust)

ConfigFunc is a function that will configure a newly emitted dust particle.

type Dust

type Dust struct {
	X, Y   float64
	Vx, Vy float64
	Radius float64
	Damp   float64
	MaxVel float64
	Age    int
}

Dust represents a single particle.

func NewDust

func NewDust(x, y float64) *Dust

NewDust creates a new dust particle.

func (*Dust) AddVelocity

func (d *Dust) AddVelocity(vx, vy float64)

AddVelocity adds velocity to the current velocity for this particle.

func (*Dust) BounceCircle

func (d *Dust) BounceCircle(x, y, radius, bounce float64) bool

BounceCircle causes a particle to bounce off the specified circle.

func (*Dust) GravitateTo

func (d *Dust) GravitateTo(x, y, gravity float64)

GravitateTo pulls the particle towards the given x, y, point.

func (*Dust) GravitateToDust

func (d *Dust) GravitateToDust(part *Dust, gravity float64)

GravitateToDust pulls the particle towards the given dust particle.

func (*Dust) GravitateToPoint

func (d *Dust) GravitateToPoint(point *geom.Point, gravity float64)

GravitateToPoint pulls the particle towards the given point.

func (*Dust) Heading

func (d *Dust) Heading() float64

Heading returns the current heading of this particle.

func (*Dust) Point

func (d *Dust) Point() *geom.Point

Point returns the Point object for this dust.

func (*Dust) Pos

func (d *Dust) Pos() (float64, float64)

Pos returns the x, y position of this particle.

func (*Dust) RepelFrom

func (d *Dust) RepelFrom(x, y, radius, k float64)

RepelFrom pushes the particle towards the given x, y, point to the given radius.

func (*Dust) SetHeading

func (d *Dust) SetHeading(angle float64)

SetHeading sets the direction this particle will move in.

func (*Dust) SetRandomVelocity

func (d *Dust) SetRandomVelocity(min, max float64)

SetRandomVelocity sets a random velocity for this particle.

func (*Dust) SetVelocityHeading

func (d *Dust) SetVelocityHeading(vel, heading float64)

SetVelocityHeading sets the overal velocity and heading of this particle.

func (*Dust) SetVelocityXY

func (d *Dust) SetVelocityXY(vx, vy float64)

SetVelocityXY sets the current velocity on each axis for this particle.

func (*Dust) SpringTo

func (d *Dust) SpringTo(x, y, k float64)

SpringTo springs the particle towards the given x, y, point.

func (*Dust) SpringToDust

func (d *Dust) SpringToDust(part *Dust, gravity float64)

SpringToDust springs the particle towards the given dust particle.

func (*Dust) SpringToPoint

func (d *Dust) SpringToPoint(point *geom.Point, gravity float64)

SpringToPoint springs the particle towards the given point.

func (*Dust) SpringToRadius

func (d *Dust) SpringToRadius(x, y, radius, k float64)

SpringToRadius springs this particles to a distance away from the given x, y point.

func (*Dust) String

func (d *Dust) String() string

String returns a string representation of this dust particle.

func (*Dust) Update

func (d *Dust) Update()

Update updates this particle's position and velocity.

func (*Dust) Velocity

func (d *Dust) Velocity() float64

Velocity returns the current velocity of this particle.

func (*Dust) Wander

func (d *Dust) Wander(w float64)

Wander makes the particle wander around, Brownian motion style.

type Emitter

type Emitter struct {
	X, Y float64
	Rate int

	Age, MaxAge int
	// contains filtered or unexported fields
}

Emitter defines a dust particle emitter.

func NewEmitter

func NewEmitter(x, y float64, rate int, bin *Bin) *Emitter

NewEmitter creates a new Emitter.

func (*Emitter) Config

func (e *Emitter) Config(c ConfigFunc)

Config sets a function to configure particles created by this emitter.

func (*Emitter) Emit

func (e *Emitter) Emit()

Emit emits a number of particles.

Jump to

Keyboard shortcuts

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