.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/text_multiple_grid.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_multiple_grid.py: Text multiple grid ================== This example demonstrate how to use MultiText to show a grid of text blocks. .. GENERATED FROM PYTHON SOURCE LINES 7-67 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_text_multiple_grid_001.webp :alt: text multiple grid :srcset: /_gallery/feature_demo/images/sphx_glr_text_multiple_grid_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import numpy as np scene = gfx.Scene() scene.add(gfx.Background.from_color("#000")) # Create text object text = gfx.MultiText( anchor="top-left", anchor_offset=0.5, screen_space=False, font_size=3, material=gfx.TextMaterial(color="#fff", outline_thickness=0.2), ) scene.add(text) def pseudo_random(*seeds): seeds = np.array(seeds, float) + 317 return np.sin(np.prod(seeds)) / 2 + 1 # Create a bunch of objects, and a textBlock for each count = 0 for iy in range(10): for ix in range(10): count += 1 x = ix * 10 y = 100 - iy * 10 rgba = pseudo_random(x, y, 1), pseudo_random(x, y, 2), pseudo_random(x, y, 3), 1 ob = gfx.Mesh( gfx.plane_geometry(8, 8), gfx.MeshBasicMaterial(color=rgba), ) ob.local.x = x + 4 ob.local.y = y - 4 scene.add(ob) block = text.create_text_block() block.set_text(str(count)) block.set_position(x, y) camera = gfx.OrthographicCamera(100, 100) camera.local.position = 51, 51, 0 renderer = gfx.renderers.WgpuRenderer(RenderCanvas(size=(800, 600))) controller = gfx.PanZoomController(camera, register_events=renderer) renderer.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.784 seconds) .. _sphx_glr_download__gallery_feature_demo_text_multiple_grid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: text_multiple_grid.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: text_multiple_grid.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: text_multiple_grid.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