.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/text_contrast.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_contrast.py: Text contrast ============= Example demonstrating text on dark and light background. On the left, plain text is shown in black and white. There is a psychological effect that makes the bottom text appear thinner than the other way around (dark text on light background). The weight_offset compensates for this effect. On the right the text uses an outline to give a good appearance on any background. .. GENERATED FROM PYTHON SOURCE LINES 15-71 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_text_contrast_001.webp :alt: text contrast :srcset: /_gallery/feature_demo/images/sphx_glr_text_contrast_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx scene = gfx.Scene() scene.add(gfx.Background.from_color("#fff", "#000")) t1 = gfx.Text( text="Lorem ipsum", font_size=40, screen_space=True, material=gfx.TextMaterial(color="#fff"), ) t2 = gfx.Text( text="Lorem ipsum", font_size=40, screen_space=True, material=gfx.TextMaterial(color="#000", weight_offset=50), ) t3 = gfx.Text( text="Lorem ipsum", font_size=40, screen_space=True, material=gfx.TextMaterial( color="#fff", outline_color="#000", outline_thickness=0.15 ), ) t4 = gfx.Text( text="Lorem ipsum", font_size=40, screen_space=True, material=gfx.TextMaterial( color="#fff", outline_color="#000", outline_thickness=0.15 ), ) t1.local.position = (-1, +1, 0) t2.local.position = (-1, -1, 0) t3.local.position = (+1, +1, 0) t4.local.position = (+1, -1, 0) scene.add(t1, t2, t3, t4) camera = gfx.OrthographicCamera(4, 3) renderer = gfx.renderers.WgpuRenderer(RenderCanvas()) 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.177 seconds) .. _sphx_glr_download__gallery_feature_demo_text_contrast.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: text_contrast.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: text_contrast.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: text_contrast.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