-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
152 lines (120 loc) · 2.74 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"fmt"
"image"
"image/color"
"math/rand"
qt "github.com/etic4/quadtree"
vec "github.com/etic4/vecmath"
rl "github.com/gen2brain/raylib-go/raylib"
)
const (
// screenWidth int = 1200
// screenHeight int = 1000
pad int32 = 0
)
var (
fps int32
nbrFrames int32
maxFrames int32
screenWidth int
screenHeight int
circList []*circle
img image.Image
colors []*color.RGBA
points []*point
filename string
maxIntialCercleRay int
growSpeed float64
nbCerclesParFrame int
maxCreationTries int
qtree *qt.Quadtree
nbrComp int
pause bool
stop bool
)
func atMouseCoords() {
p := rl.GetMousePosition()
pos := vec.Vec2{X: float64(p.X), Y: float64(p.Y)}
circ := &circle{}
qtLst := []*qt.Quadtree{}
i := len(circList) - 1
for i > 0 && pos.Distance(circList[i].center) > circList[i].r {
i--
}
if i < len(circList) {
circ = circList[i]
qtLst = qtree.GetQuadtreesFor(circ.center)
}
circ.draw(rl.Red)
for _, qtree := range qtLst {
// qtree.Draw()
qtree.DrawOne()
}
}
func init() {
circList = []*circle{}
// img, pList = getBlackPixelsFromFile("fleurs.png")
// colors, points = getAllPixelsFromFile(filename)
}
func update() {
nbrFrames++
rl.BeginDrawing()
if rl.IsMouseButtonPressed(rl.MouseRightButton) {
pause = !pause
fmt.Println("Toggle Pause: ", pause)
}
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
if pause {
rl.ClearBackground(rl.Blank)
for _, c := range circList {
c.draw(rl.White)
}
atMouseCoords()
}
}
if !stop && !pause && nbrFrames < maxFrames {
rl.ClearBackground(rl.Blank)
qtree = getQtree()
// qtree.Clear()
for _, c := range circList {
qtree.Insert(c)
}
nbrComp = 0
for _, circ := range circList {
circ.grow(growSpeed)
circ.keepGrowing()
circ.draw(rl.White)
}
for i := 0; i < nbCerclesParFrame; i++ {
circ := newCircle(float64(rand.Intn(maxIntialCercleRay + 1)))
circList = append(circList, circ)
circ.draw(rl.White)
}
fmt.Println("circList", len(circList))
fmt.Println("qtree.Size()", qtree.Size())
fmt.Println("nbrComp", nbrComp)
if stop {
fmt.Println("Stopped")
}
}
rl.EndDrawing()
}
func main() {
fps = int32(60)
filename = "fleurs.png"
screenWidth, screenHeight = getWidthHeight(filename)
maxIntialCercleRay = 1
growSpeed = 0.1
nbCerclesParFrame = 100
maxFrames = fps * 60 * 5
maxCreationTries = 1000
colors, points = getAllPixelsFromFile(filename)
qtree = getQtree()
rl.InitWindow(int32(screenWidth), int32(screenHeight), "circle packing")
rl.SetTargetFPS(fps)
for !rl.WindowShouldClose() {
update()
}
rl.CloseWindow()
}