{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Shape Visuals\n\nDemonstration of PolygonVisual, EllipseVisual, RectangleVisual\nand RegularPolygon\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from vispy import app\nimport sys\nfrom vispy.scene import SceneCanvas\nfrom vispy.scene.visuals import Polygon, Ellipse, Rectangle, RegularPolygon\nfrom vispy.color import Color\n\nwhite = Color(\"#ecf0f1\")\ngray = Color(\"#121212\")\nred = Color(\"#e74c3c\")\nblue = Color(\"#2980b9\")\norange = Color(\"#e88834\")\n\ncanvas = SceneCanvas(keys='interactive', title='Polygon Example',\n show=True)\nv = canvas.central_widget.add_view()\nv.bgcolor = gray\nv.camera = 'panzoom'\n\ncx, cy = (0.2, 0.2)\nhalfx, halfy = (0.1, 0.1)\n\npoly_coords = [(cx - halfx, cy - halfy),\n (cx + halfx, cy - halfy),\n (cx + halfx, cy + halfy),\n (cx - halfx, cy + halfy)]\npoly = Polygon(poly_coords, color=red, border_color=white,\n border_width=3, parent=v.scene)\n\nellipse = Ellipse(center=(0.4, 0.2), radius=(0.1, 0.05),\n color=blue, border_width=2, border_color=white,\n num_segments=1,\n parent=v.scene)\n\nellipse.num_segments = 10\nellipse.start_angle = 0\nellipse.span_angle = 120\n\nrect = Rectangle(center=(0.6, 0.2), width=0.1, height=0.2,\n color=orange, border_color=white,\n radius=0.02, parent=v.scene)\n\nregular_poly = RegularPolygon(center=(0.8, 0.2),\n radius=0.1, sides=6, color=blue,\n border_color=white, border_width=2,\n parent=v.scene)\nif __name__ == '__main__':\n if sys.flags.interactive != 1:\n app.run()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.19" } }, "nbformat": 4, "nbformat_minor": 0 }