-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (57 loc) · 1.29 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
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"strconv"
tea "github.com/charmbracelet/bubbletea"
"github.com/joho/godotenv"
)
func main() {
updateVars()
m := model{}
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
if _, err := p.Run(); err != nil {
fmt.Println("Uh oh:", err)
os.Exit(1)
}
}
var fps = 120
var bouncey = true
var clampMinSpeed = true
var radius = 7.0
var maxSpeed = 0.5
var adjustRate = 0.025
var alignmentRate = 1.0
var cohesionRate = 1.0
var separationRate = 1.0
var targetMinSpeed = 0.01
func updateVars() {
if err := godotenv.Overload(); err != nil {
// If there's no .env file, we'll just use the defaults
return
}
envVars := map[string]interface{}{
"FPS": &fps,
"BOUNCE": &bouncey,
"CLAMP_MIN_SPEED": &clampMinSpeed,
"RADIUS": &radius,
"MAX_SPEED": &maxSpeed,
"ADJUST_RATE": &adjustRate,
"ALIGNMENT_RATE": &alignmentRate,
"COHESION_RATE": &cohesionRate,
"SEPARATION_RATE": &separationRate,
"TARGET_MIN_SPEED": &targetMinSpeed,
}
for key, ptr := range envVars {
if v := os.Getenv(key); v != "" {
switch p := ptr.(type) {
case *int:
*p, _ = strconv.Atoi(v)
case *bool:
*p, _ = strconv.ParseBool(v)
case *float64:
*p, _ = strconv.ParseFloat(v, 64)
}
}
}
}