forked from Kei18/lacam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animate.py
88 lines (72 loc) · 1.95 KB
/
animate.py
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
################################################################################
# conway.py
#
# Author: electronut.in
#
# Description:
#
# A simple Python/matplotlib implementation of Conway's Game of Life.
################################################################################
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
matplotlib.use("agg")
with open("build_debug/log.txt", 'r') as fp:
lines = len(fp.readlines())
print('Total Number of lines:', lines)
f = open("assets/den312d.map", "r")
l = open("build_debug/log.txt", "r")
f.readline()
height = (int)(f.readline().split(" ")[1])
width = (int)(f.readline().split(" ")[1])
f.readline()
agents = (int)(l.readline().split("=")[1])
ON = 255
OFF = 0
vals = [ON, OFF]
# populate grid with random on/off - more off than on
grid = np.zeros((height, width))
print(grid.shape)
for i in range(2,16):
if i==14:
coords = l.readline().split("=")[1]
coords = coords.split("),")
for a in range(agents):
splitVal = coords[a].split(",")
r = (int)(splitVal[0][1:])
c = (int)(splitVal[1])
grid[c,r] = 200
else:
print(l.readline())
for r in range(height):
row = f.readline()
for c, ch in enumerate(row):
if(c>=width):
continue
if ch=='T' or ch=='@':
grid[r,c] = ON
original_grid = grid.copy()
count = 0
def update(data):
global grid
global count
newGrid = original_grid.copy()
coords = l.readline().split(":")[1]
coords = coords.split("),")
for a in range(agents):
splitVal = coords[a].split(",")
r = (int)(splitVal[0][1:])
c = (int)(splitVal[1])
newGrid[c,r] = 140
# update data
mat.set_data(newGrid)
grid = newGrid
return [mat]
# set up animation
fig, ax = plt.subplots()
mat = ax.matshow(grid)
ani = animation.FuncAnimation(fig, update, interval=lines-16,
save_count=lines-16)
# plt.savefig('foo.png')
ani.save('animation.mp4')