.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/scene/line.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_scene_line.py: Draw a Line =========== Simple demonstration of SceneCanvas containing a single line entity as its entire scenegraph. .. GENERATED FROM PYTHON SOURCE LINES 14-53 .. image-sg:: /gallery/scene/images/sphx_glr_line_001.gif :alt: line :srcset: /gallery/scene/images/sphx_glr_line_001.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Generating points... Done | .. code-block:: Python import sys import numpy as np from vispy import app, scene canvas = scene.SceneCanvas(size=(800, 600), keys='interactive') N = 1000 pos = np.empty((N, 2), np.float32) pos[:, 0] = np.linspace(50., 750., N) # color = np.ones((N, 4), dtype=np.float32) color[:, 0] = np.linspace(0, 1, N) color[:, 1] = color[::-1, 0] lines = [] print('Generating points...') for i in range(20): pos = pos.copy() pos[:, 1] = np.random.normal(scale=5, loc=(i+1)*30, size=N) line = scene.visuals.Line(pos=pos, color=color, parent=canvas.scene) lines.append(line) line.transform = scene.transforms.STTransform() print('Done') def update(event): for line in lines: scale = [np.sin(np.pi * event.elapsed)+2, np.cos(np.pi * event.elapsed)+2] line.transform.scale = scale timer = app.Timer('auto', connect=update, start=True) if __name__ == '__main__': canvas.show() if sys.flags.interactive == 0: app.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.912 seconds) .. _sphx_glr_download_gallery_scene_line.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: line.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: line.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_