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

.. only:: html

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

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

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

.. _sphx_glr_auto_examples_07_ui_viz_radio_buttons.py:


========================================
Sphere Color Control using Radio Buttons
========================================

This example shows how to use the UI API. We will demonstrate how to
create a Sphere and control its color using radio buttons.

First, some imports.

.. GENERATED FROM PYTHON SOURCE LINES 11-16

.. code-block:: Python


    import numpy as np

    import fury








.. GENERATED FROM PYTHON SOURCE LINES 17-18

First we need to fetch some icons that are included in FURY.

.. GENERATED FROM PYTHON SOURCE LINES 18-21

.. code-block:: Python


    fury.data.fetch_viz_icons()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Data size is approximately 12KB
    Dataset is already in place. If you want to fetch it again please first remove the folder /Users/skoudoro/.fury/icons 

    ({'icomoon.tar.gz': ('https://digital.lib.washington.edu/researchworks/bitstream/handle/1773/38478/icomoon.tar.gz', 'BC1FEEA6F58BA3601D6A0B029EB8DFC5F352E21F2A16BA41099A96AA3F5A4735')}, '/Users/skoudoro/.fury/icons')



.. GENERATED FROM PYTHON SOURCE LINES 22-26

Sphere and Radio Buttons
========================

Add a Sphere to the scene.

.. GENERATED FROM PYTHON SOURCE LINES 26-59

.. code-block:: Python


    sphere = fury.actor.sphere(
        centers=np.array([[50, 0, 0]]),
        colors=np.array([[0, 0, 1]]),
        radii=11.0,
        theta=360,
        phi=360,
    )

    # Creating a dict of possible options and mapping it with their values.
    options = {"Blue": (0, 0, 255), "Red": (255, 0, 0), "Green": (0, 255, 0)}

    color_toggler = fury.ui.RadioButton(
        list(options),
        checked_labels=["Blue"],
        padding=1,
        font_size=16,
        font_family="Arial",
        position=(200, 200),
    )


    # A callback which will set the values for the box
    def toggle_color(radio):
        vcolors = fury.utils.colors_from_actor(sphere)
        color = options[radio.checked_labels[0]]
        vcolors[:] = np.array(color)
        fury.utils.update_actor(sphere)


    color_toggler.on_change = toggle_color









.. GENERATED FROM PYTHON SOURCE LINES 60-65

Show Manager
============

Now that all the elements have been initialised, we add them to the show
manager.

.. GENERATED FROM PYTHON SOURCE LINES 65-72

.. code-block:: Python


    current_size = (800, 800)
    show_manager = fury.window.ShowManager(size=current_size, title="FURY Sphere Example")

    show_manager.scene.add(sphere)
    show_manager.scene.add(color_toggler)








.. GENERATED FROM PYTHON SOURCE LINES 73-74

Set camera for better visualization

.. GENERATED FROM PYTHON SOURCE LINES 74-87

.. code-block:: Python


    show_manager.scene.reset_camera()
    show_manager.scene.set_camera(position=(0, 0, 150))
    show_manager.scene.reset_clipping_range()
    show_manager.scene.azimuth(30)
    interactive = False

    if interactive:
        show_manager.start()

    fury.window.record(
        scene=show_manager.scene, size=current_size, out_path="viz_radio_buttons.png"
    )



.. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_radio_buttons_001.png
   :alt: viz radio buttons
   :srcset: /auto_examples/07_ui/images/sphx_glr_viz_radio_buttons_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_auto_examples_07_ui_viz_radio_buttons.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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