-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatePlay.py
49 lines (40 loc) · 1.43 KB
/
animatePlay.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
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np
import json
def import_data(filename):
# Daten aus der JSON-Datei lesen
with open(filename, 'r') as file:
data = json.load(file)
return data
def create_grid(radius):
x = np.linspace(-radius, radius, 50)
y = np.linspace(-radius, radius, 50)
X, Y = np.meshgrid(x, y)
Z = np.zeros_like(X)
return X, Y, Z
def animatePlay(frames, radius, fps):
X, Y, Z = create_grid(radius) # Koordinatenraster erstellen
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim([-radius, radius])
ax.set_ylim([-radius, radius])
ax.set_zlim([-radius, radius]) # Z-Achse angepasst
surf = None
def animate(i):
nonlocal surf
if surf:
surf.remove()
frame_data = frames[i]
for x, y, z in frame_data:
# Umrechnen der Koordinaten in Indizes
ix = np.searchsorted(X[0], x)
iy = np.searchsorted(Y[:, 0], y)
Z[iy, ix] = z
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='viridis', edgecolor='none')
return fig,
anim = FuncAnimation(fig, animate, frames=len(frames), interval=1000/(fps), repeat=True)
plt.show()
filename = "/home/alex/Dokumente/VsCode/Skripte/Python_Skript/Laser_Sound_Simulation/animation_data.json"
frames = import_data(filename)
animatePlay(frames, 40, 200)