.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/other/two_canvases.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_other_two_canvases.py: Two Canvases ============ Example demonstrating rendering the same scene into two different canvases. .. GENERATED FROM PYTHON SOURCE LINES 7-65 .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la # Create two canvases and two renderers canvas_a = RenderCanvas(size=(500, 300)) canvas_b = RenderCanvas(size=(300, 500)) renderer_b = gfx.renderers.WgpuRenderer(canvas_b) renderer_a = gfx.renderers.WgpuRenderer(canvas_a) # Compose a 3D scene with 2 objects scene = gfx.Scene() geometry1 = gfx.box_geometry(200, 200, 200) material1 = gfx.MeshPhongMaterial(color=(1, 1, 0, 1.0)) cube = gfx.Mesh(geometry1, material1) scene.add(cube) positions = np.array( [[-1, -1, 0], [-1, +1, 0], [+1, +1, 0], [+1, -1, 0], [-1, -1, 0], [+1, +1, 0]], np.float32, ) geometry2 = gfx.Geometry(positions=positions * 250) material2 = gfx.LineMaterial(thickness=5.0, color=(0.8, 0.0, 0.2, 1.0)) line = gfx.Line(geometry2, material2) scene.add(line) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.local.z = 400 scene.add(camera.add(gfx.DirectionalLight())) # Define animation functions. Each renders the scene into its own canvas. def animate_a(): rot = la.quat_from_euler((0.005, 0.01), order="XY") cube.local.rotation = la.quat_mul(rot, cube.local.rotation) renderer_a.render(scene, camera) canvas_a.request_draw() def animate_b(): renderer_b.render(scene, camera) canvas_b.request_draw() if __name__ == "__main__": canvas_a.request_draw(animate_a) canvas_b.request_draw(animate_b) loop.run() .. _sphx_glr_download__gallery_other_two_canvases.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: two_canvases.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: two_canvases.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: two_canvases.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