Skip to content

Commit 7795a9f

Browse files
committed
update spiral example
1 parent 105cbdb commit 7795a9f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

examples/scatter/spinning_spiral.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Spinning spiral scatter
33
=======================
44
5-
Example of a spinning spiral scatter
5+
Example of a spinning spiral scatter. Runs at 125 fps on an AMD RX 570.
66
"""
77

88
# test_example = false
@@ -12,7 +12,7 @@
1212
import fastplotlib as fpl
1313

1414
# number of points
15-
n = 100_000
15+
n = 1_000_000
1616

1717
# create data in the shape of a spiral
1818
phi = np.linspace(0, 30, n)
@@ -23,16 +23,27 @@
2323

2424
data = np.column_stack([xs, ys, zs])
2525

26-
figure = fpl.Figure(cameras="3d", size=(700, 560))
26+
figure = fpl.Figure(
27+
cameras="3d",
28+
size=(700, 560),
29+
canvas_kwargs={"max_fps": 500, "vsync": False}
30+
)
2731

2832
spiral = figure[0, 0].add_scatter(data, cmap="viridis_r", alpha=0.8)
2933

34+
jitter = np.random.normal(scale=0.01, size=n * 3).reshape((n, 3))
35+
3036

3137
def update():
3238
# rotate around y axis
3339
spiral.rotate(0.005, axis="y")
40+
3441
# add small jitter
35-
spiral.data[:] += np.random.normal(scale=0.01, size=n * 3).reshape((n, 3))
42+
spiral.data[:] += jitter
43+
# shift array to provide a random-sampling effect
44+
# without re-running a random generator on each iteration
45+
jitter[1000:] = jitter[:-1000]
46+
jitter[:1000] = jitter[-1000:]
3647

3748

3849
figure.add_animations(update)
@@ -51,10 +62,16 @@ def update():
5162
'maintain_aspect': True,
5263
'depth_range': None
5364
}
65+
5466
figure[0, 0].camera.set_state(camera_state)
5567
figure[0, 0].axes.visible = False
5668

5769

70+
if fpl.IMGUI:
71+
# show fps with imgui overlay
72+
figure.imgui_show_fps = True
73+
74+
5875
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
5976
# please see our docs for using fastplotlib interactively in ipython and jupyter
6077
if __name__ == "__main__":

0 commit comments

Comments
 (0)