-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathline3d_animation.py
More file actions
61 lines (39 loc) · 1.26 KB
/
line3d_animation.py
File metadata and controls
61 lines (39 loc) · 1.26 KB
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
"""
Simple 3D Line Animation
========================
Example showing animation with 3D lines.
"""
# test_example = false
# sphinx_gallery_pygfx_docs = 'animate 8s'
import numpy as np
import fastplotlib as fpl
# create data in the shape of a spiral
phi = np.linspace(0, 30, 200)
xs = phi * np.cos(phi)
ys = phi * np.sin(phi)
zs = phi
# make data 3d, with shape [<n_vertices>, 3]
spiral = np.column_stack([xs, ys, zs])
figure = fpl.Figure(cameras="3d", size=(700, 560))
line = figure[0,0].add_line(data=spiral, thickness=3, cmap='jet')
marker = figure[0,0].add_scatter(data=spiral[0], sizes=10, name="marker")
marker_index = 0
# a function to move the ball along the spiral
def move_marker():
global marker_index
marker_index += 1
if marker_index == spiral.shape[0]:
marker_index = 0
for subplot in figure:
subplot["marker"].data = spiral[marker_index]
# add `move_marker` to the animations
figure.add_animations(move_marker)
# remove clutter
figure[0, 0].axes.grids.xy.visible = True
figure[0, 0].axes.grids.xz.visible = True
figure.show()
# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()