.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/text_snake.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_text_snake.py: Text snake ========== Example showing a text with picking and custom layout. .. GENERATED FROM PYTHON SOURCE LINES 6-69 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_text_snake_001.webp :alt: text snake :srcset: /_gallery/feature_demo/images/sphx_glr_text_snake_001.webp :class: sphx-glr-single-img .. code-block:: default import time from wgpu.gui.auto import WgpuCanvas, run import pygfx as gfx import numpy as np renderer = gfx.renderers.WgpuRenderer(WgpuCanvas()) scene = gfx.Scene() class SnakeTextGeometry(gfx.TextGeometry): def _apply_layout(self): super()._apply_layout() for i in range(self.positions.nitems): x, y = self.positions.data[i] y += 5 * np.sin(x * 0.1 + time.time() * 2) self.positions.data[i] = x, y # Create the text s = "**Lorem ipsum** dolor sit amet, *consectetur adipiscing elit*, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." text1 = gfx.Text( SnakeTextGeometry(markdown=s, font_size=10), gfx.TextMaterial(color="#fff"), ) scene.add(text1) # Camera and controller camera = gfx.PerspectiveCamera(70, 16 / 9) camera.show_object(text1) controller = gfx.OrbitController(camera, register_events=renderer) # Put the scene in as box, with lights, for visual appeal. box = gfx.Mesh( gfx.box_geometry(1000, 1000, 1000), gfx.MeshPhongMaterial(), ) scene.add(box) scene.add(gfx.AmbientLight()) light = gfx.DirectionalLight(0.2) light.local.position = (0, 0, 1) scene.add(camera.add(light)) @renderer.add_event_handler("pointer_down") def handle_event(event): info = event.pick_info for key, val in info.items(): print(key, "=", val) def animate(): text1.geometry.apply_layout() renderer.render(scene, camera) renderer.request_draw() if __name__ == "__main__": renderer.request_draw(animate) run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 21.992 seconds) .. _sphx_glr_download__gallery_feature_demo_text_snake.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: text_snake.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: text_snake.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_