-
Notifications
You must be signed in to change notification settings - Fork 0
/
gol.go
41 lines (37 loc) · 829 Bytes
/
gol.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
package main
import (
"awesomeProject/board"
"fmt"
"image"
"image/color"
"image/gif"
"os"
"runtime"
)
func main() {
field := board.NewField(250, 250, 2, color.RGBA{225, 225, 225, 0xff})
var images []*image.Paletted
var delays []int
var mem runtime.MemStats
frames := 5000
for i := 0; i < frames; i++ {
field.Update()
img := field.GetCurrentImage()
images = append(images, img)
delays = append(delays, 0)
if i % (frames / 100) == 0 {
fmt.Printf("%d%%", (i/(frames/100)) + 1)
runtime.ReadMemStats(&mem)
fmt.Printf(" Total Allocated Memory = %v MiB\n", bToMb(mem.TotalAlloc))
}
}
f, _ := os.OpenFile("game_of_life.gif", os.O_WRONLY|os.O_CREATE, 0600)
defer f.Close()
gif.EncodeAll(f, &gif.GIF{
Image: images,
Delay: delays,
})
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}