# Examples from pyvista.examples.downloads.download_single_sphere_animation
# =========================================================================

import os
from tempfile import mkdtemp
import pyvista as pv
from pyvista import examples
filename = examples.download_single_sphere_animation(load=False)
reader = pv.PVDReader(filename)

# Write the gif to a temporary directory. Normally you would write to a local
# path.
gif_filename = os.path.join(mkdtemp(), 'single_sphere.gif')

# Generate the animation.
pl = pv.Plotter()
pl.open_gif(gif_filename)
for time_value in reader.time_values:
    reader.set_active_time_value(time_value)
    mesh = reader.read()
    _ = pl.add_mesh(mesh, smooth_shading=True)
    _ = pl.add_text(f'Time: {time_value:.0f}', color='black')
    pl.write_frame()
    pl.clear()
    pl.enable_lightkit()
pl.close()

# SEE ALSO:
#     Single Sphere Animation Dataset https://docs.pyvista.org/api/examples/dataset_gallery.html#single-sphere-animation-dataset
#     See this dataset in the Dataset Gallery for more info.
#     Dual Sphere Animation Dataset https://docs.pyvista.org/api/examples/dataset_gallery.html#dual-sphere-animation-dataset

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code

