.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/picking_points.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_feature_demo_picking_points.py: Point Picking ============= Example showing picking points. When clicking on a point, it's location is changed. With a small change, a line is shown instead. .. GENERATED FROM PYTHON SOURCE LINES 8-43 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_picking_points_001.webp :alt: picking points :srcset: /_gallery/feature_demo/images/sphx_glr_picking_points_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.renderers.WgpuRenderer(canvas) scene = gfx.Scene() xx = np.linspace(-50, 50, 10) yy = np.random.uniform(20, 50, 10) geometry = gfx.Geometry(positions=[(x, y, 0) for x, y in zip(xx, yy, strict=True)]) ob = gfx.Points( geometry, gfx.PointsMaterial(color=(0, 1, 1, 1), size=20, pick_write=True) ) scene.add(ob) camera = gfx.OrthographicCamera(120, 120) @ob.add_event_handler("pointer_down") def offset_point(event): info = event.pick_info if "vertex_index" in info: i = round(info["vertex_index"]) geometry.positions.data[i, 1] *= -1 geometry.positions.update_range(i) canvas.request_draw() if __name__ == "__main__": canvas.request_draw(lambda: renderer.render(scene, camera)) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.242 seconds) .. _sphx_glr_download__gallery_feature_demo_picking_points.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: picking_points.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: picking_points.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: picking_points.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