This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (46 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"gopkg.in/alecthomas/kingpin.v2"
"log"
"time"
)
var (
count = kingpin.Flag("count", "Number of boids").Short('c').Default("500").Uint()
maxVelocity = kingpin.Flag("max-velocity", "Number of boids").Short('v').Default("25").Float64()
xD = Dimension(kingpin.Arg("x-dimension", "Start and stop of x dimension").Default("0:100"))
yD = Dimension(kingpin.Arg("y-dimension", "Start and stop of y dimension").Default("0:100"))
zD = Dimension(kingpin.Arg("z-dimension", "Start and stop of z dimension").Default("0:100"))
)
type appContext struct {
area *Area
}
func main() {
kingpin.Version("0.7").Author("Taybin Rutkin")
kingpin.CommandLine.Help = "An implementation of boids"
kingpin.Parse()
log.Printf("x-dimension %f - %f\n", xD.Start, xD.Stop)
log.Printf("y-dimension %f - %f\n", yD.Start, yD.Stop)
log.Printf("z-dimension %f - %f\n", zD.Start, zD.Stop)
log.Printf("Boids: %d\n", *count)
log.Printf("Maximum Velocity: %f\n", *maxVelocity)
context := &appContext{
area: NewArea(xD, yD, zD),
}
setupBoids(context)
setupWeb(context)
}
func setupBoids(context *appContext) {
var lastID = 0
for i := 0; i < int(*count); i++ {
lastID = lastID + 1
boid := NewBoid(lastID)
boid.RandomizePosition(context.area)
context.area.AddBoid(boid)
}
go func() {
for {
context.area.UpdateBoids()
time.Sleep(time.Second / 2)
}
}()
}