| 1 |
""" |
| 2 |
.. _animation_example: |
| 3 |
|
| 4 |
Animation |
| 5 |
~~~~~~~~~ |
| 6 |
|
| 7 |
This example demonstrates how to create a simple animation. |
| 8 |
A timer is used with :meth:`~pyvista.Plotter.add_timer_event` |
| 9 |
to move a sphere across a scene. |
| 10 |
|
| 11 |
Inspired by `VTK Animation Examples <https://examples.vtk.org/site/Python/Utilities/Animation/>`_. |
| 12 |
""" |
| 13 |
|
| 14 |
import pyvista as pv |
| 15 |
|
| 16 |
sphere = pv.Sphere() |
| 17 |
|
| 18 |
pl = pv.Plotter() |
| 19 |
actor = pl.add_mesh(sphere) |
| 20 |
|
| 21 |
|
| 22 |
def callback(step): |
| 23 |
actor.position = [step / 100.0, step / 100.0, 0] |
| 24 |
|
| 25 |
|
| 26 |
pl.add_timer_event(max_steps=200, duration=500, callback=callback) |
| 27 |
|
| 28 |
cpos = pv.CameraPosition( |
| 29 |
position=(0.0, 0.0, 10.0), focal_point=(0.0, 0.0, 0.0), viewup=(0.0, 1.0, 0.0) |
| 30 |
) |
| 31 |
pl.show(cpos=cpos) |
| 32 |
# %% |
| 33 |
# .. tags:: widgets |