22Spinning 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
1212import 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
1818phi = np .linspace (0 , 30 , n )
2323
2424data = 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
2832spiral = 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
3137def 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
3849figure .add_animations (update )
@@ -51,10 +62,16 @@ def update():
5162 'maintain_aspect' : True ,
5263 'depth_range' : None
5364}
65+
5466figure [0 , 0 ].camera .set_state (camera_state )
5567figure [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
6077if __name__ == "__main__" :
0 commit comments