Loading boid/behaviour.go 0 → 100644 +1 −0 Original line number Diff line number Diff line package boid boid/boid.go 0 → 100644 +55 −0 Original line number Diff line number Diff line package boid // Vector3 consists of x, y, and z. type Vector3 struct { x, y, z float64 } // Boid is a simulated entity. type Boid struct { position Vector3 // location of the boid orientation float64 // velocity Vector3 // speed and direction rotation float64 // angle1 float64 // angle for neighbourhood angle2 float64 // angle for neighbourhood distance float64 // distance of neighourhood } // Frame is type Frame struct { tick int64 boids []Boid } // Create a new frame. func Create(bs []Boid) *Frame { return &Frame{ tick: 0, boids: bs, } } func (b *Boid) separation(f *Frame) *Boid { return b } func (b *Boid) alignment(f *Frame) *Boid { return b } func (b *Boid) cohesion(f *Frame) *Boid { return b } // Next calculates the next tick in the simulation. func (f *Frame) Next() *Frame { var nf *Frame nf.tick = f.tick + 1 nf.boids = make([]Boid, len(f.boids)) for i, b := range f.boids { nb := b.separation(f).alignment(f).cohesion(f) nf.boids[i] = *nb } return nf } Loading
boid/boid.go 0 → 100644 +55 −0 Original line number Diff line number Diff line package boid // Vector3 consists of x, y, and z. type Vector3 struct { x, y, z float64 } // Boid is a simulated entity. type Boid struct { position Vector3 // location of the boid orientation float64 // velocity Vector3 // speed and direction rotation float64 // angle1 float64 // angle for neighbourhood angle2 float64 // angle for neighbourhood distance float64 // distance of neighourhood } // Frame is type Frame struct { tick int64 boids []Boid } // Create a new frame. func Create(bs []Boid) *Frame { return &Frame{ tick: 0, boids: bs, } } func (b *Boid) separation(f *Frame) *Boid { return b } func (b *Boid) alignment(f *Frame) *Boid { return b } func (b *Boid) cohesion(f *Frame) *Boid { return b } // Next calculates the next tick in the simulation. func (f *Frame) Next() *Frame { var nf *Frame nf.tick = f.tick + 1 nf.boids = make([]Boid, len(f.boids)) for i, b := range f.boids { nb := b.separation(f).alignment(f).cohesion(f) nf.boids[i] = *nb } return nf }