
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/scene/polygon.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_polygon.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_scene_polygon.py:


Shape Visuals
=============

Demonstration of PolygonVisual, EllipseVisual, RectangleVisual
and RegularPolygon

.. GENERATED FROM PYTHON SOURCE LINES 12-61



.. image-sg:: /gallery/scene/images/sphx_glr_polygon_001.png
   :alt: polygon
   :srcset: /gallery/scene/images/sphx_glr_polygon_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    from vispy import app
    import sys
    from vispy.scene import SceneCanvas
    from vispy.scene.visuals import Polygon, Ellipse, Rectangle, RegularPolygon
    from vispy.color import Color

    white = Color("#ecf0f1")
    gray = Color("#121212")
    red = Color("#e74c3c")
    blue = Color("#2980b9")
    orange = Color("#e88834")

    canvas = SceneCanvas(keys='interactive', title='Polygon Example',
                         show=True)
    v = canvas.central_widget.add_view()
    v.bgcolor = gray
    v.camera = 'panzoom'

    cx, cy = (0.2, 0.2)
    halfx, halfy = (0.1, 0.1)

    poly_coords = [(cx - halfx, cy - halfy),
                   (cx + halfx, cy - halfy),
                   (cx + halfx, cy + halfy),
                   (cx - halfx, cy + halfy)]
    poly = Polygon(poly_coords, color=red, border_color=white,
                   border_width=3, parent=v.scene)

    ellipse = Ellipse(center=(0.4, 0.2), radius=(0.1, 0.05),
                      color=blue, border_width=2, border_color=white,
                      num_segments=1,
                      parent=v.scene)

    ellipse.num_segments = 10
    ellipse.start_angle = 0
    ellipse.span_angle = 120

    rect = Rectangle(center=(0.6, 0.2), width=0.1, height=0.2,
                     color=orange, border_color=white,
                     radius=0.02, parent=v.scene)

    regular_poly = RegularPolygon(center=(0.8, 0.2),
                                  radius=0.1, sides=6, color=blue,
                                  border_color=white, border_width=2,
                                  parent=v.scene)
    if __name__ == '__main__':
        if sys.flags.interactive != 1:
            app.run()


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

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


.. _sphx_glr_download_gallery_scene_polygon.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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