-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.go
More file actions
46 lines (38 loc) · 934 Bytes
/
visualization.go
File metadata and controls
46 lines (38 loc) · 934 Bytes
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
package main
import (
"image/color"
"math"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
const (
screenWidth = 2400
screenHeight = 1800
)
type Game struct {
bodies []Body
forces []Vector
root Node
trailLayer *ebiten.Image
}
func NewGame() *Game {
return &Game{
bodies: bodies,
forces: make([]Vector, len(bodies)),
root: Construct(bodies),
}
}
func (g *Game) Update() error {
BarnesHutUpdateForcesAndBodies(g.forces, g.bodies, g.root, dt)
g.forces = make([]Vector, len(bodies))
g.root = Construct(bodies)
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
for _, b := range g.bodies {
vector.FillCircle(screen, float32(b.Position.X+screenWidth/2), float32(b.Position.Y+screenHeight/2), float32(math.Pow(b.Mass, .2)), color.White, false)
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}