.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_text_anchor.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_text_anchor.py: Text anchor =========== This example shows texts with different anchors, so the text can be aligned in the scene. .. GENERATED FROM PYTHON SOURCE LINES 8-55 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_text_anchor_001.webp :alt: validate text anchor :srcset: /_gallery/validation/images/sphx_glr_validate_text_anchor_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx renderer = gfx.renderers.WgpuRenderer(RenderCanvas(size=(500, 500))) scene = gfx.Scene() def add_text(anchor, pos): obj = gfx.Text( text=anchor, anchor=anchor, font_size=20, screen_space=True, material=gfx.TextMaterial(color="#0f0", aa=True), ) obj.local.position = pos scene.add(obj) line_positions = [(0, -1), (0, 1), (-1, 0), (1, 0)] line_positions += [(-1, -1), (1, -1), (-1, 1), (1, 1)] line_positions += [(-1, -1), (-1, 1), (1, -1), (1, 1)] line = gfx.Line( gfx.Geometry(positions=[(p[0] * 50, p[1] * 50, -1) for p in line_positions]), gfx.LineSegmentMaterial(color="#00f", aa=True), ) scene.add(line) add_text("Baseline-center", (0, 0, 0)) add_text("Bottom-Left", (-50, -50, 0)) add_text("Bottom-Right", (50, -50, 0)) add_text("Top-Left", (-50, 50, 0)) add_text("Top-Right", (50, 50, 0)) add_text(" Middle-Left", (-50, 0, 0)) # Note the space for extra margin add_text("Middle-Right ", (50, 0, 0)) # Note the space for extra margin add_text("Bottom-Center", (0, -50, 0)) add_text("Top-Center", (0, 50, 0)) camera = gfx.OrthographicCamera(105, 105) renderer.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.149 seconds) .. _sphx_glr_download__gallery_validation_validate_text_anchor.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_text_anchor.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_text_anchor.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_text_anchor.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