.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_line_inf.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_validation_validate_line_inf.py: Infinite line segments ====================== Display infinite line segments. .. GENERATED FROM PYTHON SOURCE LINES 7-84 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_line_inf_001.webp :alt: validate line inf :srcset: /_gallery/validation/images/sphx_glr_validate_line_inf_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas() renderer = gfx.WgpuRenderer(canvas) scene = gfx.Scene() # Create an even number of positions in a circle t = np.linspace(0, 2 * np.pi, 22, endpoint=False, dtype=np.float32) x = np.sin(t) * 4 y = np.cos(t) * 4 positions1 = np.column_stack([x, y, np.zeros_like(x)]) # More positions positions2 = np.array( [ [-3, 0, 1], # Two points in the same position stay a single point [-3, 0, 1], [-2, -100, 1], # A vertical line, below viewport [-2, -101, 1], [-1, -101, 1], # A vertical line, dito [-1, -100, 1], [0, 101, 1], # A vertical line, above viewport [0, 100, 1], [1, 100, 1], # A vertical line [1, 101, 1], [2, 3.01, 1], # A shot line [2, 3.00, 1], [3, 3.00, 1], # A shot line [3, 3.01, 1], ], np.float32, ) # Assign color to the different line segments colors1 = np.zeros_like(positions1) colors1[:, 0] = 1 colors1[:, 1] = np.linspace(0, 1, len(colors1)) colors2 = np.ones_like(positions2) colors2[2::2, :] = 0, 0, 1 line1 = gfx.Line( gfx.Geometry(positions=positions1, colors=colors1), gfx.LineInfiniteSegmentMaterial( thickness=5.0, color_mode="face", start_is_infinite=False, dash_pattern=[0, 2], aa=True, ), ) scene.add(line1) line2 = gfx.Line( gfx.Geometry(positions=positions2, colors=colors2), gfx.LineInfiniteSegmentMaterial( thickness=10, end_is_infinite=1, color_mode="vertex", aa=True ), ) scene.add(line2) camera = gfx.OrthographicCamera(12, 12, maintain_aspect=True) controller = gfx.PanZoomController(camera, register_events=renderer) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.557 seconds) .. _sphx_glr_download__gallery_validation_validate_line_inf.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_line_inf.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_line_inf.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_line_inf.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html