flocking

package
v0.0.0-...-28575ab Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 18 Imported by: 0

README

Arche Demo – Flocking

Classical boids model, mimicking the behaviour of bird flocks or fish schools.

Each boid reacts with simple rules to it's 8 nearest neighbors. Gonum's kdtree is used to speed up the lookup of nearby individuals.

See the live demo for this example.

Documentation

Overview

Package flocking provides a flocking model, mimicking the behaviour of bird flocks or fish schools.

Index

Constants

View Source
const MaxNeighbors = 8

Variables

This section is empty.

Functions

func Run

func Run()

Types

type Heading

type Heading struct {
	Angle float64
}

// Velocity component.

type Velocity struct {
	common.Vec2f
}

Heading component

func (*Heading) Direction

func (h *Heading) Direction() common.Vec2f

Direction returns the unit vector corresponding to the heading.

func (*Heading) Wrap

func (h *Heading) Wrap()

Wrap brings the heading into rane [0, 2Pi).

type Images

type Images struct {
	Boid *ebiten.Image
}

Images resource for rendering.

func NewImages

func NewImages() Images

type Neighbors

type Neighbors struct {
	Entities [MaxNeighbors]kd.EntityLocation
	Count    int
}

Neighbors holds an entity's neighbours

type Position

type Position struct {
	common.Vec2f
}

Position component.

type Rand256

type Rand256 struct {
	R uint8
}

type SysInitBoids

type SysInitBoids struct {
	Count int
}

SysInitBoids system.

func (*SysInitBoids) Finalize

func (s *SysInitBoids) Finalize(w *ecs.World)

Finalize the system

func (*SysInitBoids) Initialize

func (s *SysInitBoids) Initialize(w *ecs.World)

Initialize the system

func (*SysInitBoids) Update

func (s *SysInitBoids) Update(w *ecs.World)

Update the system

type SysMoveBoids

type SysMoveBoids struct {
	Speed          float64
	MaxAcc         float64
	UpdateInterval int

	SeparationDist  float64
	SeparationAngle float64
	CohesionAngle   float64
	AlignmentAngle  float64

	WallDist  float64
	WallAngle float64

	MouseDist  float64
	MouseAngle float64
	// contains filtered or unexported fields
}

UISysDrawBoids is a system that draws ants.

func (*SysMoveBoids) Finalize

func (s *SysMoveBoids) Finalize(world *ecs.World)

FinalizeUI the system

func (*SysMoveBoids) Initialize

func (s *SysMoveBoids) Initialize(world *ecs.World)

InitializeUI the system

func (*SysMoveBoids) Update

func (s *SysMoveBoids) Update(world *ecs.World)

UpdateUI the system

type SysNeighbors

type SysNeighbors struct {
	Neighbors int
	Radius    float64
	BuildStep int
	// contains filtered or unexported fields
}

SysNeighbors system.

func (*SysNeighbors) Finalize

func (s *SysNeighbors) Finalize(w *ecs.World)

Finalize the system

func (*SysNeighbors) Initialize

func (s *SysNeighbors) Initialize(w *ecs.World)

Initialize the system

func (*SysNeighbors) Update

func (s *SysNeighbors) Update(w *ecs.World)

Update the system

type UISysDrawBoid

type UISysDrawBoid struct {
	Radius float32
	// contains filtered or unexported fields
}

UISysDrawBoids is a system that draws a single boid and its neighbors.

func (*UISysDrawBoid) FinalizeUI

func (s *UISysDrawBoid) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawBoid) InitializeUI

func (s *UISysDrawBoid) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawBoid) PostUpdateUI

func (s *UISysDrawBoid) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawBoid) UpdateUI

func (s *UISysDrawBoid) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysDrawBoids

type UISysDrawBoids struct {
	// contains filtered or unexported fields
}

UISysDrawBoids is a system that draws boids.

func (*UISysDrawBoids) FinalizeUI

func (s *UISysDrawBoids) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawBoids) InitializeUI

func (s *UISysDrawBoids) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawBoids) PostUpdateUI

func (s *UISysDrawBoids) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawBoids) UpdateUI

func (s *UISysDrawBoids) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysDrawBoidsLines

type UISysDrawBoidsLines struct {
	// contains filtered or unexported fields
}

UISysDrawBoidsLines is a system that draws boids.

func (*UISysDrawBoidsLines) FinalizeUI

func (s *UISysDrawBoidsLines) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawBoidsLines) InitializeUI

func (s *UISysDrawBoidsLines) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawBoidsLines) PostUpdateUI

func (s *UISysDrawBoidsLines) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawBoidsLines) UpdateUI

func (s *UISysDrawBoidsLines) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysManagePause

type UISysManagePause struct {
	// contains filtered or unexported fields
}

UISysManagePause is a simple system that transfers the pause state from the common.PauseMouseListener resource to the model's model.Systems.

func (*UISysManagePause) FinalizeUI

func (s *UISysManagePause) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysManagePause) InitializeUI

func (s *UISysManagePause) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysManagePause) PostUpdateUI

func (s *UISysManagePause) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysManagePause) UpdateUI

func (s *UISysManagePause) UpdateUI(world *ecs.World)

UpdateUI the system

Jump to

Keyboard shortcuts

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