.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/synced_video.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_synced_video.py: Synced Video Rendering ====================== Example demonstrating synced video rendering .. GENERATED FROM PYTHON SOURCE LINES 7-59 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_synced_video_001.webp :alt: synced video :srcset: /_gallery/feature_demo/images/sphx_glr_synced_video_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas(size=(512 * 3 + 100, 400), max_fps=999) renderer = gfx.renderers.WgpuRenderer(canvas, show_fps=True) scene = gfx.Scene() camera = gfx.OrthographicCamera(1800, 550) camera.local.y = 256 camera.local.scale_y = -1 camera.local.x = 1736 / 2 colormap1 = gfx.cm.plasma # Just create a 512x512 random image def create_random_image(): rand_img = np.random.rand(512, 512).astype(np.float32) * 255 return gfx.Image( gfx.Geometry(grid=gfx.Texture(rand_img, dim=2)), gfx.ImageBasicMaterial(clim=(0, 255), map=colormap1), ) images = list() img_pos = 0 for _i in range(3): images.append(create_random_image()) images[-1].local.x = img_pos img_pos += 50 + 512 scene.add(images[-1]) def animate(): # update with new random image for img in images: img.geometry.grid.data[:] = np.random.rand(512, 512).astype(np.float32) * 255 img.geometry.grid.update_range((0, 0, 0), img.geometry.grid.size) renderer.render(scene, camera) 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.547 seconds) .. _sphx_glr_download__gallery_feature_demo_synced_video.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: synced_video.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: synced_video.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: synced_video.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