
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/scene/save_animation.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_scene_save_animation.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_scene_save_animation.py:


Create and Save Animation
=========================

This example demonstrates how to create a sphere.

.. GENERATED FROM PYTHON SOURCE LINES 13-54



.. image-sg:: /gallery/scene/images/sphx_glr_save_animation_001.gif
   :alt: save animation
   :srcset: /gallery/scene/images/sphx_glr_save_animation_001.gif
   :class: sphx-glr-single-img





.. code-block:: Python


    import imageio

    from vispy import scene
    from vispy.visuals.transforms import STTransform

    output_filename = 'animation.gif'
    n_steps = 18
    step_angle = 10.
    axis = [0, 0.707, 0.707]

    canvas = scene.SceneCanvas(keys='interactive', bgcolor='white',
                               size=(800, 600), show=True)

    view = canvas.central_widget.add_view()
    view.camera = 'arcball'

    sphere1 = scene.visuals.Sphere(radius=1, method='latitude', parent=view.scene,
                                   edge_color='black')

    sphere2 = scene.visuals.Sphere(radius=1, method='ico', parent=view.scene,
                                   edge_color='black')

    sphere3 = scene.visuals.Sphere(radius=1, rows=10, cols=10, depth=10,
                                   method='cube', parent=view.scene,
                                   edge_color='black')

    sphere1.transform = STTransform(translate=[-2.5, 0, 0])
    sphere3.transform = STTransform(translate=[2.5, 0, 0])

    view.camera.set_range(x=[-3, 3])

    writer = imageio.get_writer('animation.gif')
    for i in range(n_steps * 2):
        im = canvas.render(alpha=True)
        writer.append_data(im)
        if i >= n_steps:
            view.camera.transform.rotate(step_angle, axis)
        else:
            view.camera.transform.rotate(-step_angle, axis)
    writer.close()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.565 seconds)


.. _sphx_glr_download_gallery_scene_save_animation.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: save_animation.ipynb <save_animation.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: save_animation.py <save_animation.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: save_animation.zip <save_animation.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
