Documentation ¶
Index ¶
- type Boid
- type Conf
- type Index
- type IndexBin
- type IndexKey
- type Swarm
- type Vector
- func (v Vector) Add(f float64) Vector
- func (v Vector) Addv(other Vector) Vector
- func (v Vector) Angle() float64
- func (v Vector) Div(f float64) Vector
- func (v Vector) Divv(other Vector) Vector
- func (v Vector) Dot(other Vector) float64
- func (v Vector) InRange(r float64) float64
- func (v Vector) Length() float64
- func (v Vector) Mul(f float64) Vector
- func (v Vector) Mulv(other Vector) Vector
- func (v Vector) Round() Vector
- func (v Vector) String() string
- func (v Vector) Sub(f float64) Vector
- func (v Vector) Subv(other Vector) Vector
- func (v Vector) Within(min, max Vector) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Boid ¶
Boid represents a single boid. It will try to fit in with a Swarm by: - moving towards the center of nearby Boids (Cohesion). - matching with nearby Boids' velocity (Alignment). - avoiding collisions with nearby Boids (Separation).
It can optionally move towards a target.
type Conf ¶
type Conf struct { Spawn [2]Vector // Bounding box of min/max vector where boids spawn. Seed int64 // Randomisation seed. Boids int // Number of boids to spawn. Workers int // Number of goroutines that runs boid calculations. IndexOffset int // Size (in pixels) of each "cell" in the spatial index used to group boids. // Variables used for boid movement calculation. CohesionFactor float64 AlignmentFactor float64 SeparationRange float64 SeparationFactor float64 TargetRange float64 TargetRepelFactor float64 TargetAttractFactor float64 VelocityMax float64 VelocityMin float64 }
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index groups Boids into neighbouring bins.
func (*Index) IterBounds ¶
func (*Index) IterNeighbours ¶
IterNeighbours iterates over all Boids in the same bin and the 8 neighbouring bins.
type Swarm ¶
type Swarm struct { Conf Conf Boids []*Boid Index *Index // contains filtered or unexported fields }
Swarm is a group of Boids. It is moving together most of the time.
type Vector ¶
type Vector struct {
X, Y float64
}
Vector represents a 2D vector.
func (Vector) Angle ¶
Calculates the vector angle and returns radians. To get degrees: multiply radians with 180/Pi
func (Vector) InRange ¶
Checks if vector length is within a target range. WARNING: target range r should be squared (r^2) by the caller! This odd behaviour is required for cutting down on the amount of square/square-roots needed within this function and hence provides some nice performance boost.