-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.py
56 lines (42 loc) · 1.51 KB
/
animation.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
import os
import numpy as np
import matplotlib.pyplot as plt
from utils import hex2color
class Animation:
def __init__(self, *args):
if len(args) == 1:
self.pixelsArray, = args
elif len(args) == 2:
structuresFolder, name = args
self.pixelsArray = []
for filename in sorted(os.listdir(structuresFolder)):
if filename.startswith(name + "_"):
filePath = structuresFolder + filename
array = np.loadtxt(filePath, dtype="str", comments=None)
self.pixelsArray.append(array.tolist())
def get(self, delay):
animation = []
for pixelArray in self.pixelsArray:
row = {
'time': delay,
'data': pixelArray
}
animation.append(row)
return animation
def show(self, animation, resolution):
figure = plt.figure()
figure.canvas.draw_idle()
dataEmpty = np.zeros(resolution)
image = plt.imshow(dataEmpty)
plt.show(block=False)
for frame in animation:
delay = frame["time"]
if delay > 0:
plt.pause(delay/1000)
data = frame["data"]
for i, row in enumerate(data):
for j, value in enumerate(data[i]):
data[i][j] = hex2color('#' + value)
image.set_data(np.array(data))
plt.draw()
plt.show(block=True)