.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/helpers_stats.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_helpers_stats.py: Stats helper (Manual) ===================== Demonstrates how to display performance statistics such as FPS and draw time on screen, by manually integrating it into the render loop. .. GENERATED FROM PYTHON SOURCE LINES 9-55 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_helpers_stats_001.webp :alt: helpers stats :srcset: /_gallery/feature_demo/images/sphx_glr_helpers_stats_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) # Show something scene = gfx.Scene() camera = gfx.PerspectiveCamera() box = gfx.Mesh( gfx.box_geometry(5, 5, 5), gfx.MeshPhongMaterial(color=(0.2, 0.4, 0.6, 1.0)), ) scene.add(box) camera.show_object(box, scale=2) # Let there be ... scene.add(gfx.AmbientLight()) light = gfx.DirectionalLight() light.local.position = (0, 0, 1) scene.add() # Add stats stats = gfx.Stats(viewport=renderer) def animate(): # Rotate the cube rot = la.quat_from_euler((0.005, 0.01), order="XY") box.local.rotation = la.quat_mul(rot, box.local.rotation) # Track the render time. You can enclose any # other piece of code for which you want to see time # statistics as well. with stats: renderer.render(scene, camera, flush=False) stats.render() canvas.request_draw() if __name__ == "__main__": canvas.request_draw(animate) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.228 seconds) .. _sphx_glr_download__gallery_feature_demo_helpers_stats.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: helpers_stats.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: helpers_stats.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: helpers_stats.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