.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic-pyvista-examples/animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-basic-pyvista-examples_animation.py: .. _ref_animation_example: Animation Example ----------------- This example demonstrates how to create and display animations for time-series simulation data using the PyVista backend. .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: Python import numpy as np import pyvista as pv from ansys.tools.visualization_interface import Plotter .. GENERATED FROM PYTHON SOURCE LINES 40-43 Create sample animation data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generate a series of meshes representing a wave propagation over time. .. GENERATED FROM PYTHON SOURCE LINES 43-65 .. code-block:: Python def create_wave_mesh(time_step, n_points=50): """Create a mesh with a wave pattern for a given time step.""" # Create grid x = np.linspace(-5, 5, n_points) y = np.linspace(-5, 5, n_points) x, y = np.meshgrid(x, y) # Create wave pattern that evolves over time t = time_step * 0.2 z = np.sin(np.sqrt(x**2 + y**2) - t) * np.exp(-0.1 * np.sqrt(x**2 + y**2)) # Create structured grid mesh = pv.StructuredGrid(x, y, z) mesh["displacement"] = np.abs(z).ravel() return mesh # Create 30 frames frames = [create_wave_mesh(i) for i in range(30)] .. GENERATED FROM PYTHON SOURCE LINES 66-69 Display animation with interactive controls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create and show an animation with play/pause, stop, and frame navigation. .. GENERATED FROM PYTHON SOURCE LINES 69-81 .. code-block:: Python plotter = Plotter() animation = plotter.animate( frames, fps=20, loop=True, scalar_bar_args={"title": "Displacement"} ) # Display with interactive controls animation.show() .. image-sg:: /examples/00-basic-pyvista-examples/images/sphx_glr_animation_001.png :alt: animation :srcset: /examples/00-basic-pyvista-examples/images/sphx_glr_animation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 82-93 Interactive Controls ~~~~~~~~~~~~~~~~~~~~ The animation window includes the following controls: - **Play/Pause button** (green): Start/stop animation playback - **Stop button** (red): Reset to first frame - **Previous/Next buttons** (blue): Step through frames manually - **Save GIF button** (orange): Export animation (requires imageio) - **Frame slider** (top): Jump to any frame You can rotate, zoom, and pan the view while the animation plays. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.866 seconds) .. _sphx_glr_download_examples_00-basic-pyvista-examples_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: animation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: animation.zip `